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

Commitde432ce

Browse files
author
Hiroshi Inoue
committed
Change Adjust_lo_type() so that it doesn't cause an error
even when cast functions are allowed to be volatile.
1 parent9e66243 commitde432ce

File tree

1 file changed

+71
-54
lines changed

1 file changed

+71
-54
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 71 additions & 54 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.64 2003/01/03 18:05:02 inoue Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.65 2003/01/13 04:28:55 inoue Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -123,82 +123,99 @@ CloseArchive(Archive *AHX)
123123
}
124124

125125
/*
126-
* Adjust lo type in contrib for 7.3 or later.
127-
*There must be a cast between lo and oid.
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.
128131
*/
129132
staticvoid
130133
Adjust_lo_type(ArchiveHandle*AH)
131134
{
132135
PGresult*res;
136+
intnTuples;
133137

134138
/*
135-
*The cast function lo(oid) should be immutable.
136-
*If it's volatile it should be changed to
137-
*be immutable and the cast (oid as lo)
138-
*should be created.
139+
*First check the existence of the cast oid as lo.
139140
*/
140-
res=PQexec(AH->blobConnection,"begin;"
141-
"update pg_proc set provolatile = 'i'"
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'"
142156
" where proname = 'lo'"
143157
" and pronargs = 1"
144-
" and provolatile = 'v'"
145158
" and prorettype in (select oid from pg_type where typname = 'lo')"
146159
" and proargtypes[0] in (select oid from pg_type where typname = 'oid')");
147160

148-
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
149-
die_horribly(AH,modulename,"could not adjust lo(oid) function");
150-
if (strcmp(PQcmdTuples(res),"1")==0)
151-
{
152-
PQclear(res);
153-
/* create cast */
154-
res=PQexec(AH->blobConnection,"create cast"
155-
" (oid as lo) with function lo(oid) as implicit;commit");
156-
if (!res)
157-
die_horribly(AH,modulename,"couldn't create cast (oid as lo)");
158-
}
159-
else
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));
161164
PQclear(res);
162-
/* The change is needless */
163-
res=PQexec(AH->blobConnection,"rollback");
164-
if (!res)
165-
die_horribly(AH,modulename,"rollback error");
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+
}
166177
}
167-
PQclear(res);
168178

169-
/*
170-
*The cast function oid(lo) should be immutable.
171-
*If it's volatile it should be changed to
172-
*be immutable and the cast (lo as oid)
173-
*should be created.
179+
/*
180+
*Also check the existence of the cast lo as oid.
174181
*/
175-
res=PQexec(AH->blobConnection,"begin;"
176-
"update pg_proc set provolatile = 'i'"
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'"
177197
" where proname = 'oid'"
178-
" and provolatile = 'v'"
179198
" and pronargs = 1"
180199
" and prorettype in (select oid from pg_type where typname = 'oid')"
181200
" and proargtypes[0] in (select oid from pg_type where typname = 'lo')");
182-
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
183-
die_horribly(AH,modulename,"could not adjust oid(lo) function");
184-
if (strcmp(PQcmdTuples(res),"1")==0)
185-
{
186-
PQclear(res);
187-
/* create cast */
188-
res=PQexec(AH->blobConnection,"create cast"
189-
" (lo as oid) with function oid(lo) as implicit;commit");
190-
if (!res)
191-
die_horribly(AH,modulename,"couldn't create cast (lo as oid)");
192-
}
193-
else
194-
{
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));
195205
PQclear(res);
196-
/* the change is needless */
197-
res=PQexec(AH->blobConnection,"rollback");
198-
if (!res)
199-
die_horribly(AH,modulename,"rollback error");
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+
}
200218
}
201-
PQclear(res);
202219
}
203220

204221
/* Public */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp