* Tom Lane ([EMAIL PROTECTED]) wrote: > I agree. I wonder if it wouldn't be cleaner to pass the information in > the other direction, ie, send a boolean down to PrintTocData saying "you > are sending SQL commands" or "you are sending COPY data". Then, instead > of depending only on the libpq state to decide what to do in > ExecuteSqlCommandBuf, we could cross-check: if we're sending SQL data > and the libpq state is wrong, just discard the line.
I believe the attached patch does this now. Under my test case it correctly handled things. I'm certainly happier with it this way and apologize for not realizing this better approach sooner. Please comment. Thanks! Stephen
Index: src/bin/pg_dump/pg_backup_archiver.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v retrieving revision 1.119 diff -c -r1.119 pg_backup_archiver.c *** src/bin/pg_dump/pg_backup_archiver.c 21 Jan 2006 02:16:20 -0000 1.119 --- src/bin/pg_dump/pg_backup_archiver.c 3 Feb 2006 02:47:33 -0000 *************** *** 330,339 **** --- 330,345 ---- * with libpq. */ if (te->copyStmt && strlen(te->copyStmt) > 0) + { ahprintf(AH, "%s", te->copyStmt); + AH->writingCopy = 1; + } (*AH->PrintTocDataPtr) (AH, te, ropt); + if (te->copyStmt && strlen(te->copyStmt) > 0) + AH->writingCopy = 0; + _enableTriggersIfNecessary(AH, te, ropt); } } *************** *** 1590,1595 **** --- 1596,1602 ---- AH->compression = compression; AH->pgCopyBuf = createPQExpBuffer(); + AH->writingCopy = 0; AH->sqlBuf = createPQExpBuffer(); /* Open stdout with no compression for AH output handle */ Index: src/bin/pg_dump/pg_backup_archiver.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v retrieving revision 1.68 diff -c -r1.68 pg_backup_archiver.h *** src/bin/pg_dump/pg_backup_archiver.h 15 Oct 2005 02:49:38 -0000 1.68 --- src/bin/pg_dump/pg_backup_archiver.h 3 Feb 2006 02:47:33 -0000 *************** *** 245,250 **** --- 245,251 ---- int loFd; /* BLOB fd */ int writingBlob; /* Flag */ + int writingCopy; /* Flag to indicate if we are in COPY mode */ int blobCount; /* # of blobs restored */ char *fSpec; /* Archive File Spec */ Index: src/bin/pg_dump/pg_backup_db.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v retrieving revision 1.66 diff -c -r1.66 pg_backup_db.c *** src/bin/pg_dump/pg_backup_db.c 15 Oct 2005 02:49:38 -0000 1.66 --- src/bin/pg_dump/pg_backup_db.c 3 Feb 2006 02:47:33 -0000 *************** *** 389,395 **** *--------- */ ! if (PQputline(AH->connection, AH->pgCopyBuf->data) != 0) die_horribly(AH, modulename, "error returned by PQputline\n"); resetPQExpBuffer(AH->pgCopyBuf); --- 389,395 ---- *--------- */ ! if (AH->pgCopyIn && PQputline(AH->connection, AH->pgCopyBuf->data) != 0) die_horribly(AH, modulename, "error returned by PQputline\n"); resetPQExpBuffer(AH->pgCopyBuf); *************** *** 400,406 **** if (isEnd) { ! if (PQendcopy(AH->connection) != 0) die_horribly(AH, modulename, "error returned by PQendcopy\n"); AH->pgCopyIn = 0; --- 400,406 ---- if (isEnd) { ! if (AH->pgCopyIn && PQendcopy(AH->connection) != 0) die_horribly(AH, modulename, "error returned by PQendcopy\n"); AH->pgCopyIn = 0; *************** *** 615,621 **** /* Could switch between command and COPY IN mode at each line */ while (qry < eos) { ! if (AH->pgCopyIn) qry = _sendCopyLine(AH, qry, eos); else qry = _sendSQLLine(AH, qry, eos); --- 615,624 ---- /* Could switch between command and COPY IN mode at each line */ while (qry < eos) { ! /* 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->writingCopy) qry = _sendCopyLine(AH, qry, eos); else qry = _sendSQLLine(AH, qry, eos);
---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match