summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_db.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-03-03 23:38:30 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-03-03 23:38:30 +0000
commitdecdaf3592dfa05642373a7bffcb431e45cc5aac (patch)
treee994bb79bcc1772b1166967e06f226d9984ef90f /src/bin/pg_dump/pg_backup_db.c
parent0b1b010c12d6682d0b9d4802f6b014aaef61dfcd (diff)
downloadpostgresql-decdaf3592dfa05642373a7bffcb431e45cc5aac.tar.gz
Improve pg_dump and psql to use libpq's newer COPY support routines,
instead of the old deprecated ones. Volkan Yazici, with some editorializing by moi.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_db.c')
-rw-r--r--src/bin/pg_dump/pg_backup_db.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 531ddb9e56..77c4086d3d 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.69 2006/02/12 06:11:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.70 2006/03/03 23:38:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -391,22 +391,29 @@ _sendCopyLine(ArchiveHandle *AH, char *qry, char *eos)
* enter COPY mode; this allows us to behave reasonably when trying
* to continue after an error in a COPY command.
*/
- if (AH->pgCopyIn && PQputline(AH->connection, AH->pgCopyBuf->data) != 0)
- die_horribly(AH, modulename, "error returned by PQputline: %s",
+ if (AH->pgCopyIn &&
+ PQputCopyData(AH->connection, AH->pgCopyBuf->data,
+ AH->pgCopyBuf->len) <= 0)
+ die_horribly(AH, modulename, "error returned by PQputCopyData: %s",
PQerrorMessage(AH->connection));
resetPQExpBuffer(AH->pgCopyBuf);
- /*
- * fprintf(stderr, "Buffer is '%s'\n", AH->pgCopyBuf->data);
- */
-
- if (isEnd)
+ if (isEnd && AH->pgCopyIn)
{
- if (AH->pgCopyIn && PQendcopy(AH->connection) != 0)
- die_horribly(AH, modulename, "error returned by PQendcopy: %s",
+ PGresult *res;
+
+ if (PQputCopyEnd(AH->connection, NULL) <= 0)
+ die_horribly(AH, 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: %s",
+ PQerrorMessage(AH->connection));
+ PQclear(res);
+
AH->pgCopyIn = false;
}