mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Cleaner solution to the problem of loading pre-7.3 dumps containing
columns of type lo (see contrib/lo). Rather than hacking the function definitions on-the-fly, just modify the queries issued by FixupBlobRefs so that they work even if CREATE CAST hasn't been issued.
This commit is contained in:
parent
90ad65a8ab
commit
af30b95618
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.62.2.1 2003/01/27 00:23:49 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.62.2.2 2003/02/01 22:07:14 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1459,7 +1459,7 @@ WriteInt(ArchiveHandle *AH, int i)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a bit yucky, but I don't want to make the binary format
|
* This is a bit yucky, but I don't want to make the binary format
|
||||||
* very dependant on representation, and not knowing much about it, I
|
* very dependent on representation, and not knowing much about it, I
|
||||||
* write out a sign byte. If you change this, don't forget to change
|
* write out a sign byte. If you change this, don't forget to change
|
||||||
* the file version #, and modify readInt to read the new format AS
|
* the file version #, and modify readInt to read the new format AS
|
||||||
* WELL AS the old formats.
|
* WELL AS the old formats.
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Implements the basic DB functions used by the archiver.
|
* Implements the basic DB functions used by the archiver.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.43 2002/10/22 19:15:23 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.43.2.1 2003/02/01 22:07:14 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -589,7 +589,6 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
|
|||||||
*uRes;
|
*uRes;
|
||||||
int i,
|
int i,
|
||||||
n;
|
n;
|
||||||
char *attr;
|
|
||||||
|
|
||||||
if (strcmp(te->tag, BLOB_XREF_TABLE) == 0)
|
if (strcmp(te->tag, BLOB_XREF_TABLE) == 0)
|
||||||
return;
|
return;
|
||||||
@ -604,7 +603,7 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
|
|||||||
fmtId(te->tag));
|
fmtId(te->tag));
|
||||||
|
|
||||||
appendPQExpBuffer(tblQry,
|
appendPQExpBuffer(tblQry,
|
||||||
"SELECT a.attname FROM "
|
"SELECT a.attname, t.typname FROM "
|
||||||
"pg_catalog.pg_attribute a, pg_catalog.pg_type t "
|
"pg_catalog.pg_attribute a, pg_catalog.pg_type t "
|
||||||
"WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass "
|
"WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass "
|
||||||
"AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')",
|
"AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')",
|
||||||
@ -623,22 +622,52 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
|
|||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
|
char *attr;
|
||||||
|
char *typname;
|
||||||
|
bool typeisoid;
|
||||||
|
|
||||||
attr = PQgetvalue(res, i, 0);
|
attr = PQgetvalue(res, i, 0);
|
||||||
|
typname = PQgetvalue(res, i, 1);
|
||||||
|
|
||||||
|
typeisoid = (strcmp(typname, "oid") == 0);
|
||||||
|
|
||||||
ahlog(AH, 1, "fixing large object cross-references for %s.%s\n",
|
ahlog(AH, 1, "fixing large object cross-references for %s.%s\n",
|
||||||
te->tag, attr);
|
te->tag, attr);
|
||||||
|
|
||||||
resetPQExpBuffer(tblQry);
|
resetPQExpBuffer(tblQry);
|
||||||
|
|
||||||
/* Can't use fmtId twice in one call... */
|
/*
|
||||||
|
* Note: we use explicit typename() cast style here because if we
|
||||||
|
* are dealing with a dump from a pre-7.3 database containing LO
|
||||||
|
* columns, the dump probably will not have CREATE CAST commands
|
||||||
|
* for lo<->oid conversions. What it will have is functions,
|
||||||
|
* which we will invoke as functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Can't use fmtId more than once per call... */
|
||||||
appendPQExpBuffer(tblQry,
|
appendPQExpBuffer(tblQry,
|
||||||
"UPDATE %s SET %s = %s.newOid",
|
"UPDATE %s SET %s = ",
|
||||||
tblName->data, fmtId(attr),
|
tblName->data, fmtId(attr));
|
||||||
|
if (typeisoid)
|
||||||
|
appendPQExpBuffer(tblQry,
|
||||||
|
"%s.newOid",
|
||||||
|
BLOB_XREF_TABLE);
|
||||||
|
else
|
||||||
|
appendPQExpBuffer(tblQry,
|
||||||
|
"%s(%s.newOid)",
|
||||||
|
fmtId(typname),
|
||||||
BLOB_XREF_TABLE);
|
BLOB_XREF_TABLE);
|
||||||
appendPQExpBuffer(tblQry,
|
appendPQExpBuffer(tblQry,
|
||||||
" FROM %s WHERE %s.oldOid = %s.%s",
|
" FROM %s WHERE %s.oldOid = ",
|
||||||
BLOB_XREF_TABLE,
|
|
||||||
BLOB_XREF_TABLE,
|
BLOB_XREF_TABLE,
|
||||||
|
BLOB_XREF_TABLE);
|
||||||
|
if (typeisoid)
|
||||||
|
appendPQExpBuffer(tblQry,
|
||||||
|
"%s.%s",
|
||||||
|
tblName->data, fmtId(attr));
|
||||||
|
else
|
||||||
|
appendPQExpBuffer(tblQry,
|
||||||
|
"oid(%s.%s)",
|
||||||
tblName->data, fmtId(attr));
|
tblName->data, fmtId(attr));
|
||||||
|
|
||||||
ahlog(AH, 10, "SQL: %s\n", tblQry->data);
|
ahlog(AH, 10, "SQL: %s\n", tblQry->data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user