diff options
Diffstat (limited to 'src/bin/pg_dump/pg_backup_db.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_db.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index a843eacc0c8..b315e681926 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -30,13 +30,13 @@ static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char * static void notice_processor(void *arg, const char *message); static int -_parse_version(ArchiveHandle *AH, const char *versionString) +_parse_version(const char *versionString) { int v; v = parse_version(versionString); if (v < 0) - die_horribly(AH, modulename, "could not parse version string \"%s\"\n", versionString); + exit_horribly(modulename, "could not parse version string \"%s\"\n", versionString); return v; } @@ -48,13 +48,13 @@ _check_database_version(ArchiveHandle *AH) const char *remoteversion_str; int remoteversion; - myversion = _parse_version(AH, PG_VERSION); + myversion = _parse_version(PG_VERSION); remoteversion_str = PQparameterStatus(AH->connection, "server_version"); if (!remoteversion_str) - die_horribly(AH, modulename, "could not get server_version from libpq\n"); + exit_horribly(modulename, "could not get server_version from libpq\n"); - remoteversion = _parse_version(AH, remoteversion_str); + remoteversion = _parse_version(remoteversion_str); AH->public.remoteVersionStr = pg_strdup(remoteversion_str); AH->public.remoteVersion = remoteversion; @@ -67,7 +67,7 @@ _check_database_version(ArchiveHandle *AH) { write_msg(NULL, "server version: %s; %s version: %s\n", remoteversion_str, progname, PG_VERSION); - die_horribly(AH, NULL, "aborting because of server version mismatch\n"); + exit_horribly(NULL, "aborting because of server version mismatch\n"); } } @@ -145,7 +145,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser) { password = simple_prompt("Password: ", 100, false); if (password == NULL) - die_horribly(AH, modulename, "out of memory\n"); + exit_horribly(modulename, "out of memory\n"); } do @@ -176,12 +176,12 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser) free(values); if (!newConn) - die_horribly(AH, modulename, "failed to reconnect to database\n"); + exit_horribly(modulename, "failed to reconnect to database\n"); if (PQstatus(newConn) == CONNECTION_BAD) { if (!PQconnectionNeedsPassword(newConn)) - die_horribly(AH, modulename, "could not reconnect to database: %s", + exit_horribly(modulename, "could not reconnect to database: %s", PQerrorMessage(newConn)); PQfinish(newConn); @@ -197,10 +197,10 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser) if (AH->promptPassword != TRI_NO) password = simple_prompt("Password: ", 100, false); else - die_horribly(AH, modulename, "connection needs password\n"); + exit_horribly(modulename, "connection needs password\n"); if (password == NULL) - die_horribly(AH, modulename, "out of memory\n"); + exit_horribly(modulename, "out of memory\n"); new_pass = true; } } while (new_pass); @@ -238,13 +238,13 @@ ConnectDatabase(Archive *AHX, bool new_pass; if (AH->connection) - die_horribly(AH, modulename, "already connected to a database\n"); + exit_horribly(modulename, "already connected to a database\n"); if (prompt_password == TRI_YES && password == NULL) { password = simple_prompt("Password: ", 100, false); if (password == NULL) - die_horribly(AH, modulename, "out of memory\n"); + exit_horribly(modulename, "out of memory\n"); } AH->promptPassword = prompt_password; @@ -280,7 +280,7 @@ ConnectDatabase(Archive *AHX, free(values); if (!AH->connection) - die_horribly(AH, modulename, "failed to connect to database\n"); + exit_horribly(modulename, "failed to connect to database\n"); if (PQstatus(AH->connection) == CONNECTION_BAD && PQconnectionNeedsPassword(AH->connection) && @@ -290,7 +290,7 @@ ConnectDatabase(Archive *AHX, PQfinish(AH->connection); password = simple_prompt("Password: ", 100, false); if (password == NULL) - die_horribly(AH, modulename, "out of memory\n"); + exit_horribly(modulename, "out of memory\n"); new_pass = true; } } while (new_pass); @@ -299,7 +299,7 @@ ConnectDatabase(Archive *AHX, /* check to see that the backend connection was successfully made */ if (PQstatus(AH->connection) == CONNECTION_BAD) - die_horribly(AH, modulename, "connection to database \"%s\" failed: %s", + exit_horribly(modulename, "connection to database \"%s\" failed: %s", PQdb(AH->connection), PQerrorMessage(AH->connection)); /* check for version mismatch */ @@ -331,6 +331,14 @@ notice_processor(void *arg, const char *message) write_msg(NULL, "%s", message); } +/* Like exit_horribly(), but with a complaint about a particular query. */ +static void +die_on_query_failure(ArchiveHandle *AH, const char *modulename, const char *query) +{ + write_msg(modulename, "query failed: %s", + PQerrorMessage(AH->connection)); + exit_horribly(modulename, "query was: %s\n", query); +} void ExecuteSqlStatement(Archive *AHX, const char *query) @@ -393,8 +401,8 @@ ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc) errStmt[DB_MAX_ERR_STMT - 2] = '.'; errStmt[DB_MAX_ERR_STMT - 1] = '\0'; } - warn_or_die_horribly(AH, modulename, "%s: %s Command was: %s\n", - desc, PQerrorMessage(conn), errStmt); + warn_or_exit_horribly(AH, modulename, "%s: %s Command was: %s\n", + desc, PQerrorMessage(conn), errStmt); break; } @@ -495,8 +503,8 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen) */ if (AH->pgCopyIn && PQputCopyData(AH->connection, buf, bufLen) <= 0) - die_horribly(AH, modulename, "error returned by PQputCopyData: %s", - PQerrorMessage(AH->connection)); + exit_horribly(modulename, "error returned by PQputCopyData: %s", + PQerrorMessage(AH->connection)); } else if (AH->outputKind == OUTPUT_OTHERDATA) { @@ -541,14 +549,14 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) PGresult *res; if (PQputCopyEnd(AH->connection, NULL) <= 0) - die_horribly(AH, modulename, "error returned by PQputCopyEnd: %s", - PQerrorMessage(AH->connection)); + exit_horribly(modulename, "error returned by PQputCopyEnd: %s", + PQerrorMessage(AH->connection)); /* Check command status and return to normal libpq state */ res = PQgetResult(AH->connection); if (PQresultStatus(res) != PGRES_COMMAND_OK) - warn_or_die_horribly(AH, modulename, "COPY failed for table \"%s\": %s", - te->tag, PQerrorMessage(AH->connection)); + warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s", + te->tag, PQerrorMessage(AH->connection)); PQclear(res); AH->pgCopyIn = false; |