*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.99 1999/01/18 06:32:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.100 1999/01/21 22:53:36 momjian Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
int schemaOnly;
int dataOnly;
int aclsOption;
+bool drop_schema;
char g_opaque_type[10]; /* name for the opaque type */
"usage: %s [options] dbname\n", progname);
fprintf(stderr,
"\t -a \t\t dump out only the data, no schema\n");
+ fprintf(stderr,
+ "\t -c \t\t clean(drop) schema prior to create\n");
fprintf(stderr,
"\t -d \t\t dump data as proper insert strings\n");
fprintf(stderr,
g_verbose = false;
force_quotes = true;
+ drop_schema = false;
strcpy(g_comment_start, "-- ");
g_comment_end[0] = '\0';
progname = *argv;
- while ((c = getopt(argc, argv, "adDf:h:nNop:st:vzu")) != EOF)
+ while ((c = getopt(argc, argv, "acdDf:h:nNop:st:vzu")) != EOF)
{
switch (c)
{
case 'a': /* Dump data only */
dataOnly = 1;
break;
+ case 'c': /* clean (i.e., drop) schema prior to create */
+ drop_schema = true;
+ break;
case 'd': /* dump data as proper insert strings */
dumpData = 1;
break;
exit_nicely(g_conn);
}
tgfunc = finfo[findx].proname;
+
+#if 0
+ /* XXX - how to emit this DROP TRIGGER? */
+ if (drop_schema)
+ {
+ sprintf(query, "DROP TRIGGER %s ON %s;\n",
+ fmtId(PQgetvalue(res2, i2, i_tgname), force_quotes),
+ fmtId(tblinfo[i].relname, force_quotes));
+ fputs(query, fout);
+ }
+#endif
+
sprintf(query, "CREATE TRIGGER %s ", fmtId(PQgetvalue(res2, i2, i_tgname), force_quotes));
/* Trigger type */
findx = 0;
becomeUser(fout, tinfo[i].usename);
+ if (drop_schema)
+ {
+ sprintf(q, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes));
+ fputs(q, fout);
+ }
+
sprintf(q,
"CREATE TYPE %s "
"( internallength = %s, externallength = %s, input = %s, "
lanname = checkForQuote(PQgetvalue(res, i, i_lanname));
lancompiler = checkForQuote(PQgetvalue(res, i, i_lancompiler));
+ if (drop_schema)
+ fprintf(fout, "DROP PROCEDURAL LANGUAGE '%s';\n", lanname);
+
fprintf(fout, "CREATE %sPROCEDURAL LANGUAGE '%s' "
"HANDLER %s LANCOMPILER '%s';\n",
(PQgetvalue(res, i, i_lanpltrusted)[0] == 't') ? "TRUSTED " : "",
PQclear(res);
}
+ if (drop_schema)
+ {
+ sprintf(q, "DROP FUNCTION %s (", fmtId(finfo[i].proname, force_quotes));
+ for (j = 0; j < finfo[i].nargs; j++)
+ {
+ char *typname;
+
+ typname = findTypeByOid(tinfo, numTypes, finfo[i].argtypes[j]);
+ sprintf(q, "%s%s%s",
+ q,
+ (j > 0) ? "," : "",
+ fmtId(typname, false));
+ }
+ sprintf (q, "%s);\n", q);
+ fputs(q, fout);
+ }
+
sprintf(q, "CREATE FUNCTION %s (", fmtId(finfo[i].proname, force_quotes));
for (j = 0; j < finfo[i].nargs; j++)
{
becomeUser(fout, oprinfo[i].usename);
+ if (drop_schema)
+ {
+ sprintf(q, "DROP OPERATOR %s (%s, %s);\n", oprinfo[i].oprname,
+ fmtId(findTypeByOid(tinfo, numTypes, oprinfo[i].oprleft), false),
+ fmtId(findTypeByOid(tinfo, numTypes, oprinfo[i].oprright), false));
+ fputs(q, fout);
+ }
+
sprintf(q,
"CREATE OPERATOR %s "
"(PROCEDURE = %s %s %s %s %s %s %s %s %s);\n ",
becomeUser(fout, agginfo[i].usename);
+ if (drop_schema)
+ {
+ sprintf(q, "DROP AGGREGATE %s %s;\n", agginfo[i].aggname,
+ fmtId(findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype), false));
+ fputs(q, fout);
+ }
+
sprintf(q, "CREATE AGGREGATE %s ( %s %s%s %s%s %s );\n",
agginfo[i].aggname,
basetype,
becomeUser(fout, tblinfo[i].usename);
+ if (drop_schema)
+ {
+ sprintf(q, "DROP TABLE %s;\n", fmtId(tblinfo[i].relname, force_quotes));
+ fputs(q, fout);
+ }
+
sprintf(q, "CREATE TABLE %s (\n\t", fmtId(tblinfo[i].relname, force_quotes));
actual_atts = 0;
for (j = 0; j < tblinfo[i].numatts; j++)
strcpy(id1, fmtId(indinfo[i].indexrelname, force_quotes));
strcpy(id2, fmtId(indinfo[i].indrelname, force_quotes));
+
+ if (drop_schema)
+ {
+ sprintf(q, "DROP INDEX %s;\n", id1);
+ fputs(q, fout);
+ }
+
fprintf(fout, "CREATE %s INDEX %s on %s using %s (",
(strcmp(indinfo[i].indisunique, "t") == 0) ? "UNIQUE" : "",
id1,
PQclear(res);
+ if (drop_schema)
+ {
+ sprintf(query, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes));
+ fputs(query, fout);
+ }
+
sprintf(query,
"CREATE SEQUENCE %s start %d increment %d maxvalue %d "
"minvalue %d cache %d %s;\n",