1515 *
1616 *
1717 * IDENTIFICATION
18- *$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.35 2001/10/25 05:49:52 momjian Exp $
18+ *$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.36 2001/11/04 04: 05:36 pjw Exp $
1919 *
2020 * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121 *
5757 * - Make allowance for data entries that did not have a data dumper
5858 *routine (eg. SEQUENCE SET)
5959 *
60+ * Modifications - 01-Nov-2001 - pjw@rhyme.com.au
61+ * - Fix handling of {data/schema}-only restores when using a full
62+ * backup file; prior version was restoring schema in data-only
63+ *restores. Added enum to make code easier to understand.
64+ *
6065 *-------------------------------------------------------------------------
6166 */
6267
7075#include "pqexpbuffer.h"
7176#include "libpq/libpq-fs.h"
7277
78+ typedef enum _teReqs_ {
79+ REQ_SCHEMA = 1 ,
80+ REQ_DATA = 2 ,
81+ REQ_ALL = REQ_SCHEMA + REQ_DATA
82+ }teReqs ;
83+
7384static void _SortToc (ArchiveHandle * AH ,TocSortCompareFn fn );
7485static int _tocSortCompareByOIDNum (const void * p1 ,const void * p2 );
7586static int _tocSortCompareByIDNum (const void * p1 ,const void * p2 );
@@ -80,7 +91,7 @@ static int_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt,
8091static void _reconnectAsOwner (ArchiveHandle * AH ,const char * dbname ,TocEntry * te );
8192static void _reconnectAsUser (ArchiveHandle * AH ,const char * dbname ,const char * user );
8293
83- static int _tocEntryRequired (TocEntry * te ,RestoreOptions * ropt );
94+ static teReqs _tocEntryRequired (TocEntry * te ,RestoreOptions * ropt );
8495static void _disableTriggersIfNecessary (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt );
8596static void _enableTriggersIfNecessary (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt );
8697static TocEntry * _getTocEntry (ArchiveHandle * AH ,int id );
@@ -155,7 +166,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
155166{
156167ArchiveHandle * AH = (ArchiveHandle * )AHX ;
157168TocEntry * te = AH -> toc -> next ;
158- int reqs ;
169+ teReqs reqs ;
159170OutputContext sav ;
160171int impliedDataOnly ;
161172bool defnDumped ;
@@ -221,7 +232,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
221232while (te != AH -> toc )
222233{
223234reqs = _tocEntryRequired (te ,ropt );
224- if ((reqs & 1 )!= 0 )
235+ if ((reqs & REQ_SCHEMA )!= 0 )
225236{/* It's schema, and it's wanted */
226237impliedDataOnly = 0 ;
227238break ;
@@ -258,7 +269,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
258269while (te != AH -> toc )
259270{
260271reqs = _tocEntryRequired (te ,ropt );
261- if (((reqs & 1 )!= 0 )&& te -> dropStmt )
272+ if (((reqs & REQ_SCHEMA )!= 0 )&& te -> dropStmt )
262273{
263274/* We want the schema */
264275ahlog (AH ,1 ,"dropping %s %s\n" ,te -> desc ,te -> name );
@@ -292,7 +303,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
292303
293304defnDumped = false;
294305
295- if ((reqs & 1 )!= 0 )/* We want the schema */
306+ if ((reqs & REQ_SCHEMA )!= 0 )/* We want the schema */
296307{
297308/* Reconnect if necessary */
298309_reconnectAsOwner (AH ,NULL ,te );
@@ -312,7 +323,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
312323/*
313324 * If we have a data component, then process it
314325 */
315- if ((reqs & 2 )!= 0 )
326+ if ((reqs & REQ_DATA )!= 0 )
316327{
317328/*
318329 * hadDumper will be set if there is genuine data component
@@ -325,7 +336,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
325336/*
326337 * If we can output the data, then restore it.
327338 */
328- if (AH -> PrintTocDataPtr != NULL && (reqs & 2 )!= 0 )
339+ if (AH -> PrintTocDataPtr != NULL && (reqs & REQ_DATA )!= 0 )
329340{
330341#ifndef HAVE_LIBZ
331342if (AH -> compression != 0 )
@@ -415,7 +426,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
415426
416427reqs = _tocEntryRequired (te ,ropt );
417428
418- if ((reqs & 2 )!= 0 )/* We loaded the data */
429+ if ((reqs & REQ_DATA )!= 0 )/* We loaded the data */
419430{
420431ahlog (AH ,1 ,"fixing up large object cross-reference for %s\n" ,te -> name );
421432FixupBlobRefs (AH ,te -> name );
@@ -1840,10 +1851,10 @@ ReadToc(ArchiveHandle *AH)
18401851}
18411852}
18421853
1843- static int
1854+ static teReqs
18441855_tocEntryRequired (TocEntry * te ,RestoreOptions * ropt )
18451856{
1846- int res = 3 ;/* Schema = 1, Data = 2, Both = 3 */
1857+ teReqs res = 3 ;/* Schema = 1, Data = 2, Both = 3 */
18471858
18481859/* If it's an ACL, maybe ignore it */
18491860if (ropt -> aclsSkip && strcmp (te -> desc ,"ACL" )== 0 )
@@ -1887,21 +1898,27 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
18871898return 0 ;
18881899}
18891900
1890- /* Special Case: If 'SEQUENCE SET' then it is considered a data entry */
1891- if (strcmp (te -> desc ,"SEQUENCE SET" )== 0 )
1892- res = res & 2 ;
1901+ /* Check if we had a dataDumper. Indicates if the entry is schema or data */
1902+ if (!te -> hadDumper ) {
1903+ /* Special Case: If 'SEQUENCE SET' then it is considered a data entry */
1904+ if (strcmp (te -> desc ,"SEQUENCE SET" )== 0 ) {
1905+ res = res & REQ_DATA ;
1906+ }else {
1907+ res = res & ~REQ_DATA ;
1908+ }
1909+ }
18931910
18941911/* Mask it if we only want schema */
18951912if (ropt -> schemaOnly )
1896- res = res & 1 ;
1913+ res = res & REQ_SCHEMA ;
18971914
18981915/* Mask it we only want data */
18991916if (ropt -> dataOnly )
1900- res = res & 2 ;
1917+ res = res & REQ_DATA ;
19011918
19021919/* Mask it if we don't have a schema contribition */
19031920if (!te -> defn || strlen (te -> defn )== 0 )
1904- res = res & 2 ;
1921+ res = res & ~ REQ_SCHEMA ;
19051922
19061923/* Finally, if we used a list, limit based on that as well */
19071924if (ropt -> limitToList && !ropt -> idWanted [te -> id - 1 ])