Commit bb30d49a authored by Philip Warner's avatar Philip Warner

- Don't dump COMMENTs in data-only dumps

 - Fix view dumping SQL for V7.0
 - Fix bug when getting view oid with long view names
 - Treat SEQUENCE SET TOC entries as data entries rather than schema
   entries.
 - Make allowance for data entries that did not have a data dumper
   routine (eg. SEQUENCE SET)
parent 5e19e14e
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.25 2001/04/25 07:03:19 pjw Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.26 2001/05/12 01:03:59 pjw Exp $
* *
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
* *
...@@ -51,6 +51,12 @@ ...@@ -51,6 +51,12 @@
* - Treat OIDs with more respect (avoid using ints, use macros for * - Treat OIDs with more respect (avoid using ints, use macros for
* conversion & comparison). * conversion & comparison).
* *
* Modifications - 10-May-2001 - pjw@rhyme.com.au
* - Treat SEQUENCE SET TOC entries as data entries rather than schema
* entries.
* - Make allowance for data entries that did not have a data dumper
* routine (eg. SEQUENCE SET)
*
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -154,6 +160,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -154,6 +160,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
int reqs; int reqs;
OutputContext sav; OutputContext sav;
int impliedDataOnly; int impliedDataOnly;
bool defnDumped;
AH->ropt = ropt; AH->ropt = ropt;
...@@ -276,6 +283,8 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -276,6 +283,8 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
} }
} }
defnDumped = false;
if ((reqs & 1) != 0) /* We want the schema */ if ((reqs & 1) != 0) /* We want the schema */
{ {
/* Reconnect if necessary */ /* Reconnect if necessary */
...@@ -283,6 +292,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -283,6 +292,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
ahlog(AH, 1, "Creating %s %s\n", te->desc, te->name); ahlog(AH, 1, "Creating %s %s\n", te->desc, te->name);
_printTocEntry(AH, te, ropt, false); _printTocEntry(AH, te, ropt, false);
defnDumped = true;
/* If we created a DB, connect to it... */ /* If we created a DB, connect to it... */
if (strcmp(te->desc, "DATABASE") == 0) if (strcmp(te->desc, "DATABASE") == 0)
...@@ -290,64 +300,82 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -290,64 +300,82 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
ahlog(AH, 1, "Connecting to new DB '%s' as %s\n", te->name, te->owner); ahlog(AH, 1, "Connecting to new DB '%s' as %s\n", te->name, te->owner);
_reconnectAsUser(AH, te->name, te->owner); _reconnectAsUser(AH, te->name, te->owner);
} }
} }
/* /*
* If we want data, and it has data, then restore that too * If we have a data component, then process it
*/ */
if (AH->PrintTocDataPtr !=NULL && (reqs & 2) != 0) if ( (reqs & 2) != 0 )
{ {
#ifndef HAVE_LIBZ /* hadDumper will be set if there is genuine data component for this
if (AH->compression != 0) * node. Otherwise, we need to check the defn field for statements
die_horribly(AH, "%s: Unable to restore data from a compressed archive\n", progname); * that need to be executed in data-only restores.
#endif
_printTocEntry(AH, te, ropt, true);
/*
* Maybe we can't do BLOBS, so check if this node is for BLOBS
*/ */
if ((strcmp(te->desc, "BLOBS") == 0) && !_canRestoreBlobs(AH)) if (te->hadDumper)
{ {
ahprintf(AH, "--\n-- SKIPPED \n--\n\n");
/* /*
* This is a bit nasty - we assume, for the moment, that * If we can output the data, then restore it.
* if a custom output is used, then we don't want
* warnings.
*/ */
if (!AH->CustomOutPtr) if (AH->PrintTocDataPtr !=NULL && (reqs & 2) != 0)
fprintf(stderr, "%s: WARNING - skipping BLOB restoration\n", progname); {
#ifndef HAVE_LIBZ
} if (AH->compression != 0)
else die_horribly(AH, "%s: Unable to restore data from a compressed archive\n",
{ progname);
#endif
_disableTriggersIfNecessary(AH, te, ropt);
/*
* Reconnect if necessary (_disableTriggers may have
* reconnected)
*/
_reconnectAsOwner(AH, "-", te);
ahlog(AH, 1, "Restoring data for %s \n", te->name);
/*
* If we have a copy statement, use it. As of V1.3, these
* are separate to allow easy import from withing a
* database connection. Pre 1.3 archives can not use DB
* connections and are sent to output only.
*
* For V1.3+, the table data MUST have a copy statement so
* that we can go into appropriate mode with libpq.
*/
if (te->copyStmt && strlen(te->copyStmt) > 0)
ahprintf(AH, te->copyStmt);
(*AH->PrintTocDataPtr) (AH, te, ropt);
_enableTriggersIfNecessary(AH, te, ropt); _printTocEntry(AH, te, ropt, true);
/*
* Maybe we can't do BLOBS, so check if this node is for BLOBS
*/
if ((strcmp(te->desc, "BLOBS") == 0) && !_canRestoreBlobs(AH))
{
ahprintf(AH, "--\n-- SKIPPED \n--\n\n");
/*
* This is a bit nasty - we assume, for the moment, that
* if a custom output is used, then we don't want
* warnings.
*/
if (!AH->CustomOutPtr)
fprintf(stderr, "%s: WARNING - skipping BLOB restoration\n", progname);
}
else
{
_disableTriggersIfNecessary(AH, te, ropt);
/*
* Reconnect if necessary (_disableTriggers may have
* reconnected)
*/
_reconnectAsOwner(AH, "-", te);
ahlog(AH, 1, "Restoring data for %s \n", te->name);
/*
* If we have a copy statement, use it. As of V1.3, these
* are separate to allow easy import from withing a
* database connection. Pre 1.3 archives can not use DB
* connections and are sent to output only.
*
* For V1.3+, the table data MUST have a copy statement so
* that we can go into appropriate mode with libpq.
*/
if (te->copyStmt && strlen(te->copyStmt) > 0)
ahprintf(AH, te->copyStmt);
(*AH->PrintTocDataPtr) (AH, te, ropt);
_enableTriggersIfNecessary(AH, te, ropt);
}
}
} else if (!defnDumped) {
/* If we haven't already dumped the defn part, do so now */
ahlog(AH, 1, "Executing %s %s\n", te->desc, te->name);
_printTocEntry(AH, te, ropt, false);
} }
} }
te = te->next; te = te->next;
...@@ -1829,26 +1857,22 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt) ...@@ -1829,26 +1857,22 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
return 0; return 0;
} }
/* Special Case: If 'SEQUENCE SET' and schemaOnly, then not needed */ /* Special Case: If 'SEQUENCE SET' then it is considered a data entry */
if (ropt->schemaOnly && (strcmp(te->desc, "SEQUENCE SET") == 0)) if (strcmp(te->desc, "SEQUENCE SET") == 0)
return 0; res = res & 2;
/* Mask it if we only want schema */ /* Mask it if we only want schema */
if (ropt->schemaOnly) if (ropt->schemaOnly)
res = res & 1; res = res & 1;
/* Mask it we only want data */ /* Mask it we only want data */
if (ropt->dataOnly && (strcmp(te->desc, "SEQUENCE SET") != 0)) if (ropt->dataOnly)
res = res & 2; res = res & 2;
/* Mask it if we don't have a schema contribition */ /* Mask it if we don't have a schema contribition */
if (!te->defn || strlen(te->defn) == 0) if (!te->defn || strlen(te->defn) == 0)
res = res & 2; res = res & 2;
/* Mask it if we don't have a possible data contribition */
if (!te->hadDumper)
res = res & 1;
/* Finally, if we used a list, limit based on that as well */ /* Finally, if we used a list, limit based on that as well */
if (ropt->limitToList && !ropt->idWanted[te->id - 1]) if (ropt->limitToList && !ropt->idWanted[te->id - 1])
return 0; return 0;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.32 2001/04/25 07:03:19 pjw Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.33 2001/05/12 01:03:59 pjw Exp $
* *
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
* - Initial version. * - Initial version.
...@@ -68,7 +68,7 @@ typedef z_stream *z_streamp; ...@@ -68,7 +68,7 @@ typedef z_stream *z_streamp;
#define K_VERS_MAJOR 1 #define K_VERS_MAJOR 1
#define K_VERS_MINOR 5 #define K_VERS_MINOR 5
#define K_VERS_REV 5 #define K_VERS_REV 6
/* Data block types */ /* Data block types */
#define BLK_DATA 1 #define BLK_DATA 1
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.205 2001/04/25 07:03:19 pjw Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.206 2001/05/12 01:03:59 pjw Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -127,6 +127,12 @@ ...@@ -127,6 +127,12 @@
* - Don't dump CHECK constraints with same source and names both * - Don't dump CHECK constraints with same source and names both
* starting with '$'. * starting with '$'.
* *
* Modifications - 10-May-2001 - pjw@rhyme.com.au
*
* - Don't dump COMMENTs in data-only dumps
* - Fix view dumping SQL for V7.0
* - Fix bug when getting view oid with long view names
*
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2047,15 +2053,37 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -2047,15 +2053,37 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
* (sequence) or 'v' (view). * (sequence) or 'v' (view).
*/ */
appendPQExpBuffer(query, if (g_fout->remoteVersion >= 70100)
{
appendPQExpBuffer(query,
"SELECT pg_class.oid, relname, relkind, relacl, " "SELECT pg_class.oid, relname, relkind, relacl, "
"(select usename from pg_user where relowner = usesysid) as usename, " "(select usename from pg_user where relowner = usesysid) as usename, "
"relchecks, reltriggers, relhasindex " "relchecks, reltriggers, relhasindex "
"from pg_class " "from pg_class "
"where relname !~ '^pg_' " "where relname !~ '^pg_' "
"and relkind in ('%c', '%c', '%c') " "and relkind in ('%c', '%c', '%c') "
"order by oid", "order by oid",
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
} else {
/*
* In 7.1, view relkind was not set to 'v', so we fake this by checking
* if we have a view by looking up pg_class & pg_rewrite.
*/
appendPQExpBuffer(query,
"SELECT c.oid, relname, relacl, "
"CASE WHEN relhasrules and relkind = 'r' "
" And EXISTS(SELECT r.rulename FROM pg_rewrite r WHERE "
" r.ev_class = c.oid AND r.ev_type = '1'::\"char\") "
"THEN 'v'::\"char\" "
"ELSE relkind End AS relkind,"
"relacl, (select usename from pg_user where relowner = usesysid) as usename, "
"relchecks, reltriggers, relhasindex "
"from pg_class c "
"where relname !~ '^pg_' "
"and relkind in ('%c', '%c', '%c') "
"order by oid",
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
}
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
if (!res || if (!res ||
...@@ -2103,9 +2131,9 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -2103,9 +2131,9 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT definition as viewdef, "); appendPQExpBuffer(query, "SELECT definition as viewdef, ");
/* XXX 7.2 - replace with att from pg_views or some other generic source */ /* XXX 7.2 - replace with att from pg_views or some other generic source */
appendPQExpBuffer(query, "(select oid from pg_rewrite where rulename='_RET'" appendPQExpBuffer(query, "(select oid from pg_rewrite where "
" || viewname) as view_oid from pg_views" " rulename=('_RET' || viewname)::name) as view_oid"
" where viewname = "); " from pg_views where viewname = ");
formatStringLiteral(query, tblinfo[i].relname, CONV_ALL); formatStringLiteral(query, tblinfo[i].relname, CONV_ALL);
appendPQExpBuffer(query, ";"); appendPQExpBuffer(query, ";");
...@@ -2974,6 +3002,10 @@ dumpComment(Archive *fout, const char *target, const char *oid) ...@@ -2974,6 +3002,10 @@ dumpComment(Archive *fout, const char *target, const char *oid)
PQExpBuffer query; PQExpBuffer query;
int i_description; int i_description;
/* Comments are SCHEMA not data */
if (dataOnly)
return;
/*** Build query to find comment ***/ /*** Build query to find comment ***/
query = createPQExpBuffer(); query = createPQExpBuffer();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment