In passing, make invocations of lo_xxx functions a bit more schema-safe.
Itagaki Takahiro
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.172 2009/06/11 14:49:07 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.173 2009/07/21 21:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Called by a format handler to initiate restoration of a blob
*/
void
-StartRestoreBlob(ArchiveHandle *AH, Oid oid)
+StartRestoreBlob(ArchiveHandle *AH, Oid oid, bool drop)
{
Oid loOid;
ahlog(AH, 2, "restoring large object with OID %u\n", oid);
+ if (drop)
+ ahprintf(AH, "SELECT CASE WHEN EXISTS(SELECT 1 FROM pg_catalog.pg_largeobject WHERE loid = '%u') THEN pg_catalog.lo_unlink('%u') END;\n",
+ oid, oid);
+
if (AH->connection)
{
loOid = lo_create(AH->connection, oid);
}
else
{
- ahprintf(AH, "SELECT lo_open(lo_create(%u), %d);\n", oid, INV_WRITE);
+ ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
+ oid, INV_WRITE);
}
AH->writingBlob = 1;
}
else
{
- ahprintf(AH, "SELECT lo_close(0);\n\n");
+ ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
}
}
/* 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", str);
AH->writingBlob = 1;
free(str);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.79 2009/06/11 14:49:07 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.80 2009/07/21 21:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
size_t WriteOffset(ArchiveHandle *, pgoff_t, int);
extern void StartRestoreBlobs(ArchiveHandle *AH);
-extern void StartRestoreBlob(ArchiveHandle *AH, Oid oid);
+extern void StartRestoreBlob(ArchiveHandle *AH, Oid oid, bool drop);
extern void EndRestoreBlob(ArchiveHandle *AH, Oid oid);
extern void EndRestoreBlobs(ArchiveHandle *AH);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.42 2009/06/11 14:49:07 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.43 2009/07/21 21:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid);
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid);
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te);
-static void _LoadBlobs(ArchiveHandle *AH);
+static void _LoadBlobs(ArchiveHandle *AH, bool drop);
static void _Clone(ArchiveHandle *AH);
static void _DeClone(ArchiveHandle *AH);
break;
case BLK_BLOBS:
- _LoadBlobs(AH);
+ _LoadBlobs(AH, ropt->dropSchema);
break;
default: /* Always have a default */
}
static void
-_LoadBlobs(ArchiveHandle *AH)
+_LoadBlobs(ArchiveHandle *AH, bool drop)
{
Oid oid;
oid = ReadInt(AH);
while (oid != 0)
{
- StartRestoreBlob(AH, oid);
+ StartRestoreBlob(AH, oid, drop);
_PrintData(AH);
EndRestoreBlob(AH, oid);
oid = ReadInt(AH);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.35 2009/02/02 20:07:37 adunstan Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.36 2009/07/21 21:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
while (oid != 0)
{
- StartRestoreBlob(AH, oid);
+ StartRestoreBlob(AH, oid, ropt->dropSchema);
_PrintFileData(AH, fname, ropt);
EndRestoreBlob(AH, oid);
_getBlobTocEntry(AH, &oid, fname);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.20 2009/02/02 20:07:37 adunstan Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.21 2009/07/21 21:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (!str)
die_horribly(AH, NULL, "out of memory\n");
- ahprintf(AH, "SELECT lowrite(0, '%s');\n", str);
+ ahprintf(AH, "SELECT pg_catalog.lowrite(0, '%s');\n", str);
free(str);
}
if (oid == 0)
die_horribly(AH, NULL, "invalid OID for large object\n");
- ahprintf(AH, "SELECT lo_open(lo_create(%u), %d);\n", oid, INV_WRITE);
+ if (AH->ropt->dropSchema)
+ ahprintf(AH, "SELECT CASE WHEN EXISTS(SELECT 1 FROM pg_catalog.pg_largeobject WHERE loid = '%u') THEN pg_catalog.lo_unlink('%u') END;\n",
+ oid, oid);
+
+ ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
+ oid, INV_WRITE);
AH->WriteDataPtr = _WriteBlobData;
}
{
AH->WriteDataPtr = _WriteData;
- ahprintf(AH, "SELECT lo_close(0);\n\n");
+ ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.65 2009/06/04 19:16:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.66 2009/07/21 21:46:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
ahlog(AH, 1, "restoring large object OID %u\n", oid);
- StartRestoreBlob(AH, oid);
+ StartRestoreBlob(AH, oid, ropt->dropSchema);
while ((cnt = tarRead(buf, 4095, th)) > 0)
{