diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-01-21 16:22:21 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-01-21 16:22:21 -0500 |
commit | 2a1ef1011548e329f4eca86671401bf4124f9d1e (patch) | |
tree | 58798b0c936832b4e70edb88fd0cb175560f5464 /src/bin/pg_dump/pg_backup_null.c | |
parent | 9de3f2843c4cf695a37d04d268df350b6118a232 (diff) | |
download | postgresql-2a1ef1011548e329f4eca86671401bf4124f9d1e.tar.gz postgresql-2a1ef1011548e329f4eca86671401bf4124f9d1e.zip |
Fix pg_restore to do the right thing when escaping large objects.
Specifically, this makes the workflow pg_dump -Fc -> pg_restore -> file
produce correct output for BLOBs when the source database has
standard_conforming_strings turned on. It was already okay when that was
off, or if pg_restore was told to restore directly into a database.
This is a back-port of commit b1732111f233bbb72788e92a627242ec28a85631 of
2009-08-04, with additional changes to emit old-style escaped bytea data
instead of hex-style. At the time, we had not heard of anyone encountering
the problem in the field, so I judged it not worth the risk of changing
back branches. Now we do have a report, from Bosco Rama, so back-patch
into 8.2 through 8.4. 9.0 and up are okay already.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_null.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_null.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/bin/pg_dump/pg_backup_null.c b/src/bin/pg_dump/pg_backup_null.c index abff1138fc2..634aa6f1759 100644 --- a/src/bin/pg_dump/pg_backup_null.c +++ b/src/bin/pg_dump/pg_backup_null.c @@ -23,6 +23,7 @@ */ #include "pg_backup_archiver.h" +#include "dumputils.h" #include <unistd.h> /* for dup */ @@ -101,16 +102,16 @@ _WriteBlobData(ArchiveHandle *AH, const void *data, size_t dLen) { if (dLen > 0) { - unsigned char *str; - size_t len; + PQExpBuffer buf = createPQExpBuffer(); - str = PQescapeBytea((const unsigned char *) data, dLen, &len); - if (!str) - die_horribly(AH, NULL, "out of memory\n"); + appendByteaLiteralAHX(buf, + (const unsigned char *) data, + dLen, + AH); - ahprintf(AH, "SELECT lowrite(0, '%s');\n", str); + ahprintf(AH, "SELECT pg_catalog.lowrite(0, %s);\n", buf->data); - free(str); + destroyPQExpBuffer(buf); } return dLen; } |