|
15 | 15 | * |
16 | 16 | * |
17 | 17 | * 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 $ |
19 | 19 | * |
20 | 20 | *------------------------------------------------------------------------- |
21 | 21 | */ |
@@ -123,82 +123,99 @@ CloseArchive(Archive *AHX) |
123 | 123 | } |
124 | 124 |
|
125 | 125 | /* |
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. |
128 | 131 | */ |
129 | 132 | staticvoid |
130 | 133 | Adjust_lo_type(ArchiveHandle*AH) |
131 | 134 | { |
132 | 135 | PGresult*res; |
| 136 | +intnTuples; |
133 | 137 |
|
134 | 138 | /* |
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. |
139 | 140 | */ |
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'" |
142 | 156 | " where proname = 'lo'" |
143 | 157 | " and pronargs = 1" |
144 | | -" and provolatile = 'v'" |
145 | 158 | " and prorettype in (select oid from pg_type where typname = 'lo')" |
146 | 159 | " and proargtypes[0] in (select oid from pg_type where typname = 'oid')"); |
147 | 160 |
|
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)); |
161 | 164 | 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 | +} |
166 | 177 | } |
167 | | -PQclear(res); |
168 | 178 |
|
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. |
174 | 181 | */ |
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'" |
177 | 197 | " where proname = 'oid'" |
178 | | -" and provolatile = 'v'" |
179 | 198 | " and pronargs = 1" |
180 | 199 | " and prorettype in (select oid from pg_type where typname = 'oid')" |
181 | 200 | " 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)); |
195 | 205 | 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 | +} |
200 | 218 | } |
201 | | -PQclear(res); |
202 | 219 | } |
203 | 220 |
|
204 | 221 | /* Public */ |
|