* - Treat OIDs with more respect (avoid using ints, use macros for
* conversion & comparison).
*
+ * - 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)
+ *
*-------------------------------------------------------------------------
*/
int reqs;
OutputContext sav;
int impliedDataOnly;
+ bool defnDumped;
AH->ropt = ropt;
}
}
+ defnDumped = false;
+
if ((reqs & 1) != 0) /* We want the schema */
{
/* Reconnect if necessary */
ahlog(AH, 1, "Creating %s %s\n", te->desc, te->name);
_printTocEntry(AH, te, ropt, false);
+ defnDumped = true;
/* If we created a DB, connect to it... */
if (strcmp(te->desc, "DATABASE") == 0)
ahlog(AH, 1, "Connecting to new DB '%s' as %s\n", 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
- if (AH->compression != 0)
- die_horribly(AH, "%s: Unable to restore data from a compressed archive\n", progname);
-#endif
-
- _printTocEntry(AH, te, ropt, true);
-
- /*
- * Maybe we can't do BLOBS, so check if this node is for BLOBS
+ /* hadDumper will be set if there is genuine data component for this
+ * node. Otherwise, we need to check the defn field for statements
+ * that need to be executed in data-only restores.
*/
- 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 a custom output is used, then we don't want
- * warnings.
+ * If we can output the data, then restore it.
*/
- 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);
+ if (AH->PrintTocDataPtr !=NULL && (reqs & 2) != 0)
+ {
+#ifndef HAVE_LIBZ
+ if (AH->compression != 0)
+ die_horribly(AH, "%s: Unable to restore data from a compressed archive\n",
+ progname);
+#endif
- _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;
return 0;
}
- /* Special Case: If 'SEQUENCE SET' and schemaOnly, then not needed */
- if (ropt->schemaOnly && (strcmp(te->desc, "SEQUENCE SET") == 0))
- return 0;
+ /* Special Case: If 'SEQUENCE SET' then it is considered a data entry */
+ if (strcmp(te->desc, "SEQUENCE SET") == 0)
+ res = res & 2;
/* Mask it if we only want schema */
if (ropt->schemaOnly)
res = res & 1;
/* Mask it we only want data */
- if (ropt->dataOnly && (strcmp(te->desc, "SEQUENCE SET") != 0))
+ if (ropt->dataOnly)
res = res & 2;
/* Mask it if we don't have a schema contribition */
if (!te->defn || strlen(te->defn) == 0)
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 */
if (ropt->limitToList && !ropt->idWanted[te->id - 1])
return 0;
* - Don't dump CHECK constraints with same source and names both
* starting with '$'.
*
+ *
+ * - 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
+ *
*-------------------------------------------------------------------------
*/
* (sequence) or 'v' (view).
*/
- appendPQExpBuffer(query,
+ if (g_fout->remoteVersion >= 70100)
+ {
+ appendPQExpBuffer(query,
"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 "
"from pg_class "
"where relname !~ '^pg_' "
"and relkind in ('%c', '%c', '%c') "
"order by oid",
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);
if (!res ||
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT definition as viewdef, ");
/* XXX 7.2 - replace with att from pg_views or some other generic source */
- appendPQExpBuffer(query, "(select oid from pg_rewrite where rulename='_RET'"
- " || viewname) as view_oid from pg_views"
- " where viewname = ");
+ appendPQExpBuffer(query, "(select oid from pg_rewrite where "
+ " rulename=('_RET' || viewname)::name) as view_oid"
+ " from pg_views where viewname = ");
formatStringLiteral(query, tblinfo[i].relname, CONV_ALL);
appendPQExpBuffer(query, ";");
PQExpBuffer query;
int i_description;
+ /* Comments are SCHEMA not data */
+ if (dataOnly)
+ return;
+
/*** Build query to find comment ***/
query = createPQExpBuffer();