*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.119 2006/01/21 02:16:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.120 2006/02/05 20:58:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* with libpq.
*/
if (te->copyStmt && strlen(te->copyStmt) > 0)
+ {
ahprintf(AH, "%s", te->copyStmt);
+ AH->writingCopyData = true;
+ }
(*AH->PrintTocDataPtr) (AH, te, ropt);
+ AH->writingCopyData = false;
+
_enableTriggersIfNecessary(AH, te, ropt);
}
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.68 2005/10/15 02:49:38 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.69 2006/02/05 20:58:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
PGconn *connection;
int connectToDB; /* Flag to indicate if direct DB connection is
* required */
- int pgCopyIn; /* Currently in libpq 'COPY IN' mode. */
+ bool writingCopyData; /* True when we are sending COPY data */
+ bool pgCopyIn; /* Currently in libpq 'COPY IN' mode. */
PQExpBuffer pgCopyBuf; /* Left-over data from incomplete lines in
* COPY IN */
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.66 2005/10/15 02:49:38 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.67 2006/02/05 20:58:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
if (PQresultStatus(res) == PGRES_COPY_IN)
{
- AH->pgCopyIn = 1;
+ AH->pgCopyIn = true;
}
else
{
appendPQExpBuffer(AH->pgCopyBuf, "%s\n", qry);
isEnd = (strcmp(AH->pgCopyBuf->data, "\\.\n") == 0);
- /*---------
- * fprintf(stderr, "Sending '%s' via
- * COPY (at end = %d)\n\n", AH->pgCopyBuf->data, isEnd);
- *---------
+ /*
+ * Note that we drop the data on the floor if libpq has failed to
+ * enter COPY mode; this allows us to behave reasonably when trying
+ * to continue after an error in a COPY command.
*/
-
- if (PQputline(AH->connection, AH->pgCopyBuf->data) != 0)
+ if (AH->pgCopyIn && PQputline(AH->connection, AH->pgCopyBuf->data) != 0)
die_horribly(AH, modulename, "error returned by PQputline\n");
resetPQExpBuffer(AH->pgCopyBuf);
if (isEnd)
{
- if (PQendcopy(AH->connection) != 0)
+ if (AH->pgCopyIn && PQendcopy(AH->connection) != 0)
die_horribly(AH, modulename, "error returned by PQendcopy\n");
- AH->pgCopyIn = 0;
+ AH->pgCopyIn = false;
}
return qry + loc + 1;
/* Could switch between command and COPY IN mode at each line */
while (qry < eos)
{
- if (AH->pgCopyIn)
+ /*
+ * If libpq is in CopyIn mode *or* if the archive structure shows we
+ * are sending COPY data, treat the data as COPY data. The pgCopyIn
+ * check is only needed for backwards compatibility with ancient
+ * archive files that might just issue a COPY command without marking
+ * it properly. Note that in an archive entry that has a copyStmt,
+ * all data up to the end of the entry will go to _sendCopyLine, and
+ * therefore will be dropped if libpq has failed to enter COPY mode.
+ * Also, if a "\." data terminator is found, anything remaining in the
+ * archive entry will be dropped.
+ */
+ if (AH->pgCopyIn || AH->writingCopyData)
qry = _sendCopyLine(AH, qry, eos);
else
qry = _sendSQLLine(AH, qry, eos);