summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_archiver.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-01-06 13:04:24 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-01-06 13:04:24 -0500
commit1f996adab3ec30c12b5ffaa418045e4b2c93d818 (patch)
tree8c6ba4fbacdc7f5ac3e5e3e99ecf47a51b64df40 /src/bin/pg_dump/pg_backup_archiver.h
parentc024a3b3be1c86459f9b47f81f61cb8a67ee2712 (diff)
Fix pg_restore's direct-to-database mode for INSERT-style table data.
In commit 6545a901aaf84cb05212bb6a7674059908f527c3, I removed the mini SQL lexer that was in pg_backup_db.c, thinking that it had no real purpose beyond separating COPY data from SQL commands, which purpose had been obsoleted by long-ago fixes in pg_dump's archive file format. Unfortunately this was in error: that code was also used to identify command boundaries in INSERT-style table data, which is run together as a single string in the archive file for better compressibility. As a result, direct-to-database restores from archive files made with --inserts or --column-inserts fail in our latest releases, as reported by Dick Visser. To fix, restore the mini SQL lexer, but simplify it by adjusting the calling logic so that it's only required to cope with INSERT-style table data, not arbitrary SQL commands. This allows us to not have to deal with SQL comments, E'' strings, or dollar-quoted strings, none of which have ever been emitted by dumpTableData_insert. Also, fix the lexer to cope with standard-conforming strings, which was the actual bug that the previous patch was meant to solve. Back-patch to all supported branches. The previous patch went back to 8.2, which unfortunately means that the EOL release of 8.2 contains this bug, but I don't think we're doing another 8.2 release just because of that.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.h')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index a3a87dcd29b..fad1bc00a9f 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -139,6 +139,20 @@ typedef struct _outputContext
typedef enum
{
+ SQL_SCAN = 0, /* normal */
+ SQL_IN_SINGLE_QUOTE, /* '...' literal */
+ SQL_IN_DOUBLE_QUOTE /* "..." identifier */
+} sqlparseState;
+
+typedef struct
+{
+ sqlparseState state; /* see above */
+ bool backSlash; /* next char is backslash quoted? */
+ PQExpBuffer curCmd; /* incomplete line (NULL if not created) */
+} sqlparseInfo;
+
+typedef enum
+{
STAGE_NONE = 0,
STAGE_INITIALIZING,
STAGE_PROCESSING,
@@ -147,6 +161,13 @@ typedef enum
typedef enum
{
+ OUTPUT_SQLCMDS = 0, /* emitting general SQL commands */
+ OUTPUT_COPYDATA, /* writing COPY data */
+ OUTPUT_OTHERDATA /* writing data as INSERT commands */
+} ArchiverOutput;
+
+typedef enum
+{
REQ_SCHEMA = 1,
REQ_DATA = 2,
REQ_ALL = REQ_SCHEMA + REQ_DATA
@@ -172,6 +193,8 @@ typedef struct _archiveHandle
* Added V1.7 */
ArchiveFormat format; /* Archive format */
+ sqlparseInfo sqlparse; /* state for parsing INSERT data */
+
time_t createDate; /* Date archive created */
/*
@@ -222,7 +245,7 @@ typedef struct _archiveHandle
PGconn *connection;
int connectToDB; /* Flag to indicate if direct DB connection is
* required */
- bool writingCopyData; /* True when we are sending COPY data */
+ ArchiverOutput outputKind; /* Flag for what we're currently writing */
bool pgCopyIn; /* Currently in libpq 'COPY IN' mode. */
int loFd; /* BLOB fd */