pg_dump: Further reduce reliance on global variables.

This is another round of refactoring to make things simpler for parallel
pg_dump.  pg_dump.c now issues SQL queries through the relevant Archive
object, rather than relying on the global variable g_conn.  This commit
isn't quite enough to get rid of g_conn entirely, but it makes a big
dent in its utilization and, along the way, manages to be slightly less
code than before.
This commit is contained in:
Robert Haas 2012-02-07 10:07:02 -05:00
parent a347f96b99
commit 1631598ea2
5 changed files with 218 additions and 270 deletions

View File

@ -1453,6 +1453,16 @@ die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
va_end(ap);
}
/* As above, but with a complaint about a particular query. */
void
die_on_query_failure(ArchiveHandle *AH, const char *modulename,
const char *query)
{
write_msg(modulename, "query failed: %s",
PQerrorMessage(AH->connection));
die_horribly(AH, modulename, "query was: %s\n", query);
}
/* on some error, we may decide to go on... */
void
warn_or_die_horribly(ArchiveHandle *AH,

View File

@ -325,6 +325,7 @@ typedef struct _tocEntry
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4), noreturn));
extern void die_on_query_failure(ArchiveHandle *AH, const char *modulename, const char *query) __attribute__((noreturn));
extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
extern void WriteTOC(ArchiveHandle *AH);

View File

@ -318,6 +318,30 @@ notice_processor(void *arg, const char *message)
}
void
ExecuteSqlStatement(Archive *AHX, const char *query)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
PGresult *res;
res = PQexec(AH->connection, query);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
die_on_query_failure(AH, modulename, query);
PQclear(res);
}
PGresult *
ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
PGresult *res;
res = PQexec(AH->connection, query);
if (PQresultStatus(res) != status)
die_on_query_failure(AH, modulename, query);
return res;
}
/*
* Convenience function to send a query.
* Monitors result to detect COPY statements

View File

@ -12,6 +12,10 @@
extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen);
extern void ExecuteSqlStatement(Archive *AHX, const char *query);
extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
ExecStatusType status);
extern void EndDBCopyMode(ArchiveHandle *AH, struct _tocEntry * te);
extern void StartTransaction(ArchiveHandle *AH);

File diff suppressed because it is too large Load Diff