summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_archiver.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-01-21 16:22:27 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-01-21 16:22:27 -0500
commit1a1167a172ebc390437ffc5547a9f755fa56b731 (patch)
treed9eb2d21fd0e944529382edbfdb4a83ec85c8139 /src/bin/pg_dump/pg_backup_archiver.c
parentb414dde44cb91f891d1006f22b7196df54e055ea (diff)
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_archiver.c')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 880fbf1c6cd..c8db8f3dea1 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -1090,20 +1090,19 @@ dump_lo_buf(ArchiveHandle *AH)
}
else
{
- unsigned char *str;
- size_t len;
+ PQExpBuffer buf = createPQExpBuffer();
- str = PQescapeBytea((const unsigned char *) AH->lo_buf,
- AH->lo_buf_used, &len);
- if (!str)
- die_horribly(AH, modulename, "out of memory\n");
+ appendByteaLiteralAHX(buf,
+ (const unsigned char *) AH->lo_buf,
+ AH->lo_buf_used,
+ AH);
/* Hack: turn off writingBlob so ahwrite doesn't recurse to here */
AH->writingBlob = 0;
- ahprintf(AH, "SELECT lowrite(0, '%s');\n", str);
+ ahprintf(AH, "SELECT pg_catalog.lowrite(0, %s);\n", buf->data);
AH->writingBlob = 1;
- free(str);
+ destroyPQExpBuffer(buf);
}
AH->lo_buf_used = 0;
}