* mode 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;
+
/*
* If we just restored blobs, fix references in
* previously-loaded tables; otherwise, if we
STAGE_FINALIZING
} ArchiverStage;
+typedef enum
+{
+ REQ_SCHEMA = 1,
+ REQ_DATA = 2,
+ REQ_ALL = REQ_SCHEMA + REQ_DATA
+} teReqs;
+
typedef struct _archiveHandle
{
Archive public; /* Public part of archive */
int blobTxActive; /* Flag set if TX active on blobConnection */
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 */
extern void ReadToc(ArchiveHandle *AH);
extern void WriteDataChunks(ArchiveHandle *AH);
-extern int TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt);
+extern teReqs TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt);
extern bool checkSeek(FILE *fp);
/*
if (conn != AH->connection)
die_horribly(AH, modulename, "COPY command executed in non-primary connection\n");
- AH->pgCopyIn = 1;
+ AH->pgCopyIn = true;
}
else
{
*---------
*/
- 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 we are in CopyIn mode *or* if the upper-layers believe we're doing
+ * a COPY then call sendCopyLine. If we're not actually in CopyIn mode
+ * the sendCopyLine will just dump the data coming in */
+ if (AH->pgCopyIn || AH->writingCopyData)
qry = _sendCopyLine(AH, qry, eos);
else
qry = _sendSQLLine(AH, qry, eos);