|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * IDENTIFICATION
|
18 |
| - *$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.25 2001/04/25 07:03:19 pjw Exp $ |
| 18 | + *$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.26 2001/05/12 01:03:59 pjw Exp $ |
19 | 19 | *
|
20 | 20 | * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
21 | 21 | *
|
|
51 | 51 | * - Treat OIDs with more respect (avoid using ints, use macros for
|
52 | 52 | *conversion & comparison).
|
53 | 53 | *
|
| 54 | + * Modifications - 10-May-2001 - pjw@rhyme.com.au |
| 55 | + * - Treat SEQUENCE SET TOC entries as data entries rather than schema |
| 56 | + *entries. |
| 57 | + * - Make allowance for data entries that did not have a data dumper |
| 58 | + * routine (eg. SEQUENCE SET) |
| 59 | + * |
54 | 60 | *-------------------------------------------------------------------------
|
55 | 61 | */
|
56 | 62 |
|
@@ -154,6 +160,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
154 | 160 | intreqs;
|
155 | 161 | OutputContextsav;
|
156 | 162 | intimpliedDataOnly;
|
| 163 | +booldefnDumped; |
157 | 164 |
|
158 | 165 | AH->ropt=ropt;
|
159 | 166 |
|
@@ -276,78 +283,99 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
276 | 283 | }
|
277 | 284 | }
|
278 | 285 |
|
| 286 | +defnDumped= false; |
| 287 | + |
279 | 288 | if ((reqs&1)!=0)/* We want the schema */
|
280 | 289 | {
|
281 | 290 | /* Reconnect if necessary */
|
282 | 291 | _reconnectAsOwner(AH,"-",te);
|
283 | 292 |
|
284 | 293 | ahlog(AH,1,"Creating %s %s\n",te->desc,te->name);
|
285 | 294 | _printTocEntry(AH,te,ropt, false);
|
| 295 | +defnDumped= true; |
286 | 296 |
|
287 | 297 | /* If we created a DB, connect to it... */
|
288 | 298 | if (strcmp(te->desc,"DATABASE")==0)
|
289 | 299 | {
|
290 | 300 | ahlog(AH,1,"Connecting to new DB '%s' as %s\n",te->name,te->owner);
|
291 | 301 | _reconnectAsUser(AH,te->name,te->owner);
|
292 | 302 | }
|
293 |
| -} |
| 303 | +} |
294 | 304 |
|
295 | 305 | /*
|
296 |
| - * If wewant data, and it hasdata, thenrestore that too |
| 306 | + * If wehave adata component, thenprocess it |
297 | 307 | */
|
298 |
| -if (AH->PrintTocDataPtr!=NULL&&(reqs&2)!=0) |
| 308 | +if ((reqs&2)!=0) |
299 | 309 | {
|
300 |
| -#ifndefHAVE_LIBZ |
301 |
| -if (AH->compression!=0) |
302 |
| -die_horribly(AH,"%s: Unable to restore data from a compressed archive\n",progname); |
303 |
| -#endif |
304 |
| - |
305 |
| -_printTocEntry(AH,te,ropt, true); |
306 |
| - |
307 |
| -/* |
308 |
| - * Maybe we can't do BLOBS, so check if this node is for BLOBS |
| 310 | +/* hadDumper will be set if there is genuine data component for this |
| 311 | + * node. Otherwise, we need to check the defn field for statements |
| 312 | + * that need to be executed in data-only restores. |
309 | 313 | */
|
310 |
| -if ((strcmp(te->desc,"BLOBS")==0)&& !_canRestoreBlobs(AH)) |
| 314 | +if (te->hadDumper) |
311 | 315 | {
|
312 |
| -ahprintf(AH,"--\n-- SKIPPED \n--\n\n"); |
313 |
| - |
314 | 316 | /*
|
315 |
| - * This is a bit nasty - we assume, for the moment, that |
316 |
| - * if a custom output is used, then we don't want |
317 |
| - * warnings. |
| 317 | + * If we can output the data, then restore it. |
318 | 318 | */
|
319 |
| -if (!AH->CustomOutPtr) |
320 |
| -fprintf(stderr,"%s: WARNING - skipping BLOB restoration\n",progname); |
321 |
| - |
322 |
| -} |
323 |
| -else |
324 |
| -{ |
325 |
| - |
326 |
| -_disableTriggersIfNecessary(AH,te,ropt); |
327 |
| - |
328 |
| -/* |
329 |
| - * Reconnect if necessary (_disableTriggers may have |
330 |
| - * reconnected) |
331 |
| - */ |
332 |
| -_reconnectAsOwner(AH,"-",te); |
333 |
| - |
334 |
| -ahlog(AH,1,"Restoring data for %s \n",te->name); |
335 |
| - |
336 |
| -/* |
337 |
| - * If we have a copy statement, use it. As of V1.3, these |
338 |
| - * are separate to allow easy import from withing a |
339 |
| - * database connection. Pre 1.3 archives can not use DB |
340 |
| - * connections and are sent to output only. |
341 |
| - * |
342 |
| - * For V1.3+, the table data MUST have a copy statement so |
343 |
| - * that we can go into appropriate mode with libpq. |
344 |
| - */ |
345 |
| -if (te->copyStmt&&strlen(te->copyStmt)>0) |
346 |
| -ahprintf(AH,te->copyStmt); |
347 |
| - |
348 |
| -(*AH->PrintTocDataPtr) (AH,te,ropt); |
| 319 | +if (AH->PrintTocDataPtr!=NULL&& (reqs&2)!=0) |
| 320 | +{ |
| 321 | +#ifndefHAVE_LIBZ |
| 322 | +if (AH->compression!=0) |
| 323 | +die_horribly(AH,"%s: Unable to restore data from a compressed archive\n", |
| 324 | +progname); |
| 325 | +#endif |
349 | 326 |
|
350 |
| -_enableTriggersIfNecessary(AH,te,ropt); |
| 327 | +_printTocEntry(AH,te,ropt, true); |
| 328 | + |
| 329 | +/* |
| 330 | + * Maybe we can't do BLOBS, so check if this node is for BLOBS |
| 331 | + */ |
| 332 | +if ((strcmp(te->desc,"BLOBS")==0)&& !_canRestoreBlobs(AH)) |
| 333 | +{ |
| 334 | +ahprintf(AH,"--\n-- SKIPPED \n--\n\n"); |
| 335 | + |
| 336 | +/* |
| 337 | + * This is a bit nasty - we assume, for the moment, that |
| 338 | + * if a custom output is used, then we don't want |
| 339 | + * warnings. |
| 340 | + */ |
| 341 | +if (!AH->CustomOutPtr) |
| 342 | +fprintf(stderr,"%s: WARNING - skipping BLOB restoration\n",progname); |
| 343 | + |
| 344 | +} |
| 345 | +else |
| 346 | +{ |
| 347 | + |
| 348 | +_disableTriggersIfNecessary(AH,te,ropt); |
| 349 | + |
| 350 | +/* |
| 351 | + * Reconnect if necessary (_disableTriggers may have |
| 352 | + * reconnected) |
| 353 | + */ |
| 354 | +_reconnectAsOwner(AH,"-",te); |
| 355 | + |
| 356 | +ahlog(AH,1,"Restoring data for %s \n",te->name); |
| 357 | + |
| 358 | +/* |
| 359 | + * If we have a copy statement, use it. As of V1.3, these |
| 360 | + * are separate to allow easy import from withing a |
| 361 | + * database connection. Pre 1.3 archives can not use DB |
| 362 | + * connections and are sent to output only. |
| 363 | + * |
| 364 | + * For V1.3+, the table data MUST have a copy statement so |
| 365 | + * that we can go into appropriate mode with libpq. |
| 366 | + */ |
| 367 | +if (te->copyStmt&&strlen(te->copyStmt)>0) |
| 368 | +ahprintf(AH,te->copyStmt); |
| 369 | + |
| 370 | +(*AH->PrintTocDataPtr) (AH,te,ropt); |
| 371 | + |
| 372 | +_enableTriggersIfNecessary(AH,te,ropt); |
| 373 | +} |
| 374 | +} |
| 375 | +}elseif (!defnDumped) { |
| 376 | +/* If we haven't already dumped the defn part, do so now */ |
| 377 | +ahlog(AH,1,"Executing %s %s\n",te->desc,te->name); |
| 378 | +_printTocEntry(AH,te,ropt, false); |
351 | 379 | }
|
352 | 380 | }
|
353 | 381 | te=te->next;
|
@@ -1829,26 +1857,22 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
|
1829 | 1857 | return0;
|
1830 | 1858 | }
|
1831 | 1859 |
|
1832 |
| -/* Special Case: If 'SEQUENCE SET'and schemaOnly, then not needed */ |
1833 |
| -if (ropt->schemaOnly&& (strcmp(te->desc,"SEQUENCE SET")==0)) |
1834 |
| -return0; |
| 1860 | +/* Special Case: If 'SEQUENCE SET'then it is considered a data entry */ |
| 1861 | +if (strcmp(te->desc,"SEQUENCE SET")==0) |
| 1862 | +res=res&2; |
1835 | 1863 |
|
1836 | 1864 | /* Mask it if we only want schema */
|
1837 | 1865 | if (ropt->schemaOnly)
|
1838 | 1866 | res=res&1;
|
1839 | 1867 |
|
1840 | 1868 | /* Mask it we only want data */
|
1841 |
| -if (ropt->dataOnly&& (strcmp(te->desc,"SEQUENCE SET")!=0)) |
| 1869 | +if (ropt->dataOnly) |
1842 | 1870 | res=res&2;
|
1843 | 1871 |
|
1844 | 1872 | /* Mask it if we don't have a schema contribition */
|
1845 | 1873 | if (!te->defn||strlen(te->defn)==0)
|
1846 | 1874 | res=res&2;
|
1847 | 1875 |
|
1848 |
| -/* Mask it if we don't have a possible data contribition */ |
1849 |
| -if (!te->hadDumper) |
1850 |
| -res=res&1; |
1851 |
| - |
1852 | 1876 | /* Finally, if we used a list, limit based on that as well */
|
1853 | 1877 | if (ropt->limitToList&& !ropt->idWanted[te->id-1])
|
1854 | 1878 | return0;
|
|