Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite0a1ee2

Browse files
committed
Cleaner solution to the problem of loading pre-7.3 dumps containing
columns of type lo (see contrib/lo). Rather than hacking the functiondefinitions on-the-fly, just modify the queries issued by FixupBlobRefsso that they work even if CREATE CAST hasn't been issued.
1 parent330b4e4 commite0a1ee2

File tree

2 files changed

+40
-108
lines changed

2 files changed

+40
-108
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.66 2003/01/27 00:23:38 tgl Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.67 2003/02/01 22:06:59 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -122,102 +122,6 @@ CloseArchive(Archive *AHX)
122122
die_horribly(AH,modulename,"could not close the output file in CloseArchive\n");
123123
}
124124

125-
/*
126-
*This function repairs a slip when upgrading PG cast
127-
*mechanism from 7.2 or earlier to 7.3 or later.
128-
*The casts between lo and oid are needed when retrieving
129-
*lo type data in FixupBlobRefs and so adjust lo type in
130-
*contrib before processing FixupBlobRefs.
131-
*/
132-
staticvoid
133-
Adjust_lo_type(ArchiveHandle*AH)
134-
{
135-
PGresult*res;
136-
intnTuples;
137-
138-
/*
139-
*First check the existence of the cast oid as lo.
140-
*/
141-
res=PQexec(AH->blobConnection,"select 1 from pg_cast where"
142-
" castsource in (select oid from pg_type where typname = 'oid')"
143-
" and casttarget in (select oid from pg_type where typname = 'lo')");
144-
145-
if (!res||PQresultStatus(res)!=PGRES_TUPLES_OK)
146-
die_horribly(AH,modulename,"error while checking the cast oid as lo\n");
147-
nTuples=PQntuples(res);
148-
PQclear(res);
149-
if (nTuples==0)
150-
{
151-
/*
152-
*Check the existence of the cast function lo(oid)
153-
*and change it to be IMMUTABLE.
154-
*/
155-
res=PQexec(AH->blobConnection,"update pg_proc set provolatile = 'i'"
156-
" where proname = 'lo'"
157-
" and pronargs = 1"
158-
" and prorettype in (select oid from pg_type where typname = 'lo')"
159-
" and proargtypes[0] in (select oid from pg_type where typname = 'oid')");
160-
161-
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
162-
die_horribly(AH,modulename,"could not adjust lo(oid) function\n");
163-
nTuples=atoi(PQcmdTuples(res));
164-
PQclear(res);
165-
if (nTuples==1)
166-
{
167-
/*
168-
*The cast function lo(oid) exists and
169-
*then create the correspoding cast.
170-
*/
171-
res=PQexec(AH->blobConnection,"create cast"
172-
" (oid as lo) with function lo(oid) as implicit");
173-
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
174-
die_horribly(AH,modulename,"couldn't create cast (oid as lo)\n");
175-
PQclear(res);
176-
}
177-
}
178-
179-
/*
180-
*Also check the existence of the cast lo as oid.
181-
*/
182-
res=PQexec(AH->blobConnection,"select 1 from pg_cast where"
183-
" castsource in (select oid from pg_type where typname = 'lo')"
184-
" and casttarget in (select oid from pg_type where typname = 'oid')");
185-
186-
if (!res||PQresultStatus(res)!=PGRES_TUPLES_OK)
187-
die_horribly(AH,modulename,"error while checking the cast lo as oid\n");
188-
nTuples=PQntuples(res);
189-
PQclear(res);
190-
if (nTuples==0)
191-
{
192-
/*
193-
*Check the existence of the cast function oid(lo)
194-
*and change it to be IMMUTABLE.
195-
*/
196-
res=PQexec(AH->blobConnection,"update pg_proc set provolatile = 'i'"
197-
" where proname = 'oid'"
198-
" and pronargs = 1"
199-
" and prorettype in (select oid from pg_type where typname = 'oid')"
200-
" and proargtypes[0] in (select oid from pg_type where typname = 'lo')");
201-
202-
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
203-
die_horribly(AH,modulename,"could not adjust oid(lo) function\n");
204-
nTuples=atoi(PQcmdTuples(res));
205-
PQclear(res);
206-
if (nTuples==1)
207-
{
208-
/*
209-
*The cast function oid(lo) exists and
210-
*then create the correspoding cast.
211-
*/
212-
res=PQexec(AH->blobConnection,"create cast"
213-
" (lo as oid) with function oid(lo) as implicit");
214-
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
215-
die_horribly(AH,modulename,"couldn't create cast (lo as oid)\n");
216-
PQclear(res);
217-
}
218-
}
219-
}
220-
221125
/* Public */
222126
void
223127
RestoreArchive(Archive*AHX,RestoreOptions*ropt)
@@ -453,7 +357,6 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
453357
/* NULL parameter means disable ALL user triggers */
454358
_disableTriggersIfNecessary(AH,NULL,ropt);
455359

456-
Adjust_lo_type(AH);
457360
te=AH->toc->next;
458361
while (te!=AH->toc)
459362
{

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.43 2002/10/22 19:15:23 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.44 2003/02/01 22:06:59 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -589,7 +589,6 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
589589
*uRes;
590590
inti,
591591
n;
592-
char*attr;
593592

594593
if (strcmp(te->tag,BLOB_XREF_TABLE)==0)
595594
return;
@@ -604,7 +603,7 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
604603
fmtId(te->tag));
605604

606605
appendPQExpBuffer(tblQry,
607-
"SELECT a.attname FROM "
606+
"SELECT a.attname, t.typname FROM "
608607
"pg_catalog.pg_attribute a, pg_catalog.pg_type t "
609608
"WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass "
610609
"AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')",
@@ -623,23 +622,53 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
623622

624623
for (i=0;i<n;i++)
625624
{
625+
char*attr;
626+
char*typname;
627+
booltypeisoid;
628+
626629
attr=PQgetvalue(res,i,0);
630+
typname=PQgetvalue(res,i,1);
631+
632+
typeisoid= (strcmp(typname,"oid")==0);
627633

628634
ahlog(AH,1,"fixing large object cross-references for %s.%s\n",
629635
te->tag,attr);
630636

631637
resetPQExpBuffer(tblQry);
632638

633-
/* Can't use fmtId twice in one call... */
639+
/*
640+
* Note: we use explicit typename() cast style here because if we
641+
* are dealing with a dump from a pre-7.3 database containing LO
642+
* columns, the dump probably will not have CREATE CAST commands
643+
* for lo<->oid conversions. What it will have is functions,
644+
* which we will invoke as functions.
645+
*/
646+
647+
/* Can't use fmtId more than once per call... */
634648
appendPQExpBuffer(tblQry,
635-
"UPDATE %s SET %s = %s.newOid",
636-
tblName->data,fmtId(attr),
637-
BLOB_XREF_TABLE);
649+
"UPDATE %s SET %s = ",
650+
tblName->data,fmtId(attr));
651+
if (typeisoid)
652+
appendPQExpBuffer(tblQry,
653+
"%s.newOid",
654+
BLOB_XREF_TABLE);
655+
else
656+
appendPQExpBuffer(tblQry,
657+
"%s(%s.newOid)",
658+
fmtId(typname),
659+
BLOB_XREF_TABLE);
638660
appendPQExpBuffer(tblQry,
639-
" FROM %s WHERE %s.oldOid = %s.%s",
640-
BLOB_XREF_TABLE,
661+
" FROM %s WHERE %s.oldOid = ",
641662
BLOB_XREF_TABLE,
642-
tblName->data,fmtId(attr));
663+
BLOB_XREF_TABLE);
664+
if (typeisoid)
665+
appendPQExpBuffer(tblQry,
666+
"%s.%s",
667+
tblName->data,fmtId(attr));
668+
else
669+
appendPQExpBuffer(tblQry,
670+
"oid(%s.%s)",
671+
tblName->data,fmtId(attr));
643672

644673
ahlog(AH,10,"SQL: %s\n",tblQry->data);
645674

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp