aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-08-16 02:25:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-08-16 02:25:23 +0000
commit7e9308544f041cf59e0dd4916fe93fee9aa91f99 (patch)
tree8e7a3660a5c7f0eb0d5b64e810d28756773e4d3a
parent7a9b6cd47259e4d5ee4330e6b38fa021dbc111cd (diff)
downloadpostgresql-7e9308544f041cf59e0dd4916fe93fee9aa91f99.tar.gz
postgresql-7e9308544f041cf59e0dd4916fe93fee9aa91f99.zip
Fix pg_dump/pg_restore's ExecuteSqlCommand() to behave suitably if PQexec
returns NULL instead of a PGresult. The former coding would fail, which is OK, but it neglected to give you the PQerrorMessage that might tell you why. In the oldest branches, there was another problem: it'd sometimes report PQerrorMessage from the wrong connection.
-rw-r--r--src/bin/pg_dump/pg_backup_db.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 3cb29b0d346..8048c716be1 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.66.2.2 2006/02/09 18:28:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.66.2.3 2008/08/16 02:25:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -293,19 +293,23 @@ ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc)
PGresult *res;
char errStmt[DB_MAX_ERR_STMT];
- /* fprintf(stderr, "Executing: '%s'\n\n", qry->data); */
+#ifdef NOT_USED
+ fprintf(stderr, "Executing: '%s'\n\n", qry->data);
+#endif
res = PQexec(conn, qry->data);
- if (!res)
- die_horribly(AH, modulename, "%s: no result from server\n", desc);
- if (PQresultStatus(res) != PGRES_COMMAND_OK && PQresultStatus(res) != PGRES_TUPLES_OK)
+ switch (PQresultStatus(res))
{
- if (PQresultStatus(res) == PGRES_COPY_IN)
- {
+ case PGRES_COMMAND_OK:
+ case PGRES_TUPLES_OK:
+ /* A-OK */
+ break;
+ case PGRES_COPY_IN:
+ /* Assume this is an expected result */
AH->pgCopyIn = true;
- }
- else
- {
+ break;
+ default:
+ /* trouble */
strncpy(errStmt, qry->data, DB_MAX_ERR_STMT);
if (errStmt[DB_MAX_ERR_STMT - 1] != '\0')
{
@@ -315,9 +319,7 @@ ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc)
errStmt[DB_MAX_ERR_STMT - 1] = '\0';
}
warn_or_die_horribly(AH, modulename, "%s: %s Command was: %s\n",
- desc, PQerrorMessage(AH->connection),
- errStmt);
- }
+ desc, PQerrorMessage(conn), errStmt);
}
PQclear(res);