|
22 | 22 | *
|
23 | 23 | *
|
24 | 24 | * IDENTIFICATION
|
25 |
| - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.193 2001/02/18 18:33:59 momjian Exp $ |
| 25 | + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.194 2001/03/06 04:53:28 pjw Exp $ |
26 | 26 | *
|
27 | 27 | * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
|
28 | 28 | *
|
|
106 | 106 | * - Fix help output: replace 'f' with 't' and change desc.
|
107 | 107 | * - Add extra arg to formatStringLiteral to specify how to handle LF & TAB.
|
108 | 108 | * I opted for encoding them except in procedure bodies.
|
| 109 | + * - Dump relevant parts of sequences only when doing schemaOnly & dataOnly |
| 110 | + * - Prevent double-dumping of sequences when dataOnly. |
109 | 111 | *
|
110 | 112 | *-------------------------------------------------------------------------
|
111 | 113 | */
|
@@ -156,7 +158,7 @@ typedef enum _formatLiteralOptions {
|
156 | 158 | } formatLiteralOptions;
|
157 | 159 |
|
158 | 160 | static void dumpComment(Archive *outfile, const char *target, const char *oid);
|
159 |
| -static void dumpSequence(Archive *fout, TableInfo tbinfo); |
| 161 | +static void dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool dataOnly); |
160 | 162 | static void dumpACL(Archive *fout, TableInfo tbinfo);
|
161 | 163 | static void dumpTriggers(Archive *fout, const char *tablename,
|
162 | 164 | TableInfo *tblinfo, int numTables);
|
@@ -608,24 +610,6 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
|
608 | 610 | (onlytable == NULL || (strlen(onlytable) == 0)) ? "s" : "",
|
609 | 611 | g_comment_end);
|
610 | 612 |
|
611 |
| - /* Dump SEQUENCEs first (if dataOnly) */ |
612 |
| - if (dataOnly) |
613 |
| - { |
614 |
| - for (i = 0; i < numTables; i++) |
615 |
| - { |
616 |
| - if (!(tblinfo[i].sequence)) |
617 |
| - continue; |
618 |
| - if (!onlytable || (strcmp(tblinfo[i].relname, onlytable) == 0) || (strlen(onlytable) == 0) ) |
619 |
| - { |
620 |
| - if (g_verbose) |
621 |
| - fprintf(stderr, "%s dumping out schema of sequence '%s' %s\n", |
622 |
| - g_comment_start, tblinfo[i].relname, g_comment_end); |
623 |
| - /* becomeUser(fout, tblinfo[i].usename); */ |
624 |
| - dumpSequence(fout, tblinfo[i]); |
625 |
| - } |
626 |
| - } |
627 |
| - } |
628 |
| - |
629 | 613 | for (i = 0; i < numTables; i++)
|
630 | 614 | {
|
631 | 615 | const char *classname = tblinfo[i].relname;
|
@@ -3730,7 +3714,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
|
3730 | 3714 | || (serialSeq && !strcmp(tblinfo[i].relname, serialSeq)))
|
3731 | 3715 | {
|
3732 | 3716 | /* becomeUser(fout, tblinfo[i].usename); */
|
3733 |
| - dumpSequence(fout, tblinfo[i]); |
| 3717 | + dumpSequence(fout, tblinfo[i], schemaOnly, dataOnly); |
3734 | 3718 | if (!aclsSkip)
|
3735 | 3719 | dumpACL(fout, tblinfo[i]);
|
3736 | 3720 | }
|
@@ -4314,7 +4298,7 @@ findLastBuiltinOid(const char* dbname)
|
4314 | 4298 |
|
4315 | 4299 |
|
4316 | 4300 | static void
|
4317 |
| -dumpSequence(Archive *fout, TableInfo tbinfo) |
| 4301 | +dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool dataOnly) |
4318 | 4302 | {
|
4319 | 4303 | PGresult *res;
|
4320 | 4304 | int4 last,
|
@@ -4367,44 +4351,52 @@ dumpSequence(Archive *fout, TableInfo tbinfo)
|
4367 | 4351 | t = PQgetvalue(res, 0, 7);
|
4368 | 4352 | called = *t;
|
4369 | 4353 |
|
4370 |
| - PQclear(res); |
4371 |
| - |
4372 |
| - resetPQExpBuffer(delqry); |
4373 |
| - appendPQExpBuffer(delqry, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes)); |
4374 |
| - |
4375 | 4354 | /*
|
4376 | 4355 | * The logic we use for restoring sequences is as follows:
|
4377 | 4356 | * - Add a basic CREATE SEQUENCE statement
|
4378 | 4357 | * (use last_val for start if called == 'f', else use min_val for start_val).
|
4379 | 4358 | * - Add a 'SETVAL(seq, last_val, iscalled)' at restore-time iff we load data
|
4380 | 4359 | */
|
4381 |
| - resetPQExpBuffer(query); |
4382 |
| - appendPQExpBuffer(query, |
4383 |
| - "CREATE SEQUENCE %s start %d increment %d maxvalue %d " |
4384 |
| - "minvalue %d cache %d %s;\n", |
4385 |
| - fmtId(tbinfo.relname, force_quotes), |
4386 |
| - (called == 't') ? minv : last, |
4387 |
| - incby, maxv, minv, cache, |
4388 |
| - (cycled == 't') ? "cycle" : ""); |
4389 | 4360 |
|
4390 |
| - ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE", NULL, |
4391 |
| - query->data, delqry->data, "", tbinfo.usename, NULL, NULL); |
| 4361 | + if (!dataOnly) |
| 4362 | + { |
| 4363 | + PQclear(res); |
4392 | 4364 |
|
| 4365 | + resetPQExpBuffer(delqry); |
| 4366 | + appendPQExpBuffer(delqry, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes)); |
4393 | 4367 |
|
4394 |
| - resetPQExpBuffer(query); |
4395 |
| - appendPQExpBuffer(query, "SELECT setval ("); |
4396 |
| - formatStringLiteral(query, fmtId(tbinfo.relname, force_quotes), CONV_ALL); |
4397 |
| - appendPQExpBuffer(query, ", %d, '%c');\n", last, called); |
| 4368 | + resetPQExpBuffer(query); |
| 4369 | + appendPQExpBuffer(query, |
| 4370 | + "CREATE SEQUENCE %s start %d increment %d maxvalue %d " |
| 4371 | + "minvalue %d cache %d %s;\n", |
| 4372 | + fmtId(tbinfo.relname, force_quotes), |
| 4373 | + (called == 't') ? minv : last, |
| 4374 | + incby, maxv, minv, cache, |
| 4375 | + (cycled == 't') ? "cycle" : ""); |
| 4376 | + |
| 4377 | + ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE", NULL, |
| 4378 | + query->data, delqry->data, "", tbinfo.usename, NULL, NULL); |
| 4379 | + } |
4398 | 4380 |
|
4399 |
| - ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE SET", NULL, |
4400 |
| - query->data, "" /* Del */, "", "", NULL, NULL); |
| 4381 | + if (!schemaOnly) |
| 4382 | + { |
| 4383 | + resetPQExpBuffer(query); |
| 4384 | + appendPQExpBuffer(query, "SELECT setval ("); |
| 4385 | + formatStringLiteral(query, fmtId(tbinfo.relname, force_quotes), CONV_ALL); |
| 4386 | + appendPQExpBuffer(query, ", %d, '%c');\n", last, called); |
4401 | 4387 |
|
4402 |
| - /* Dump Sequence Comments */ |
| 4388 | + ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE SET", NULL, |
| 4389 | + query->data, "" /* Del */, "", "", NULL, NULL); |
| 4390 | + } |
4403 | 4391 |
|
4404 |
| - resetPQExpBuffer(query); |
4405 |
| - appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo.relname, force_quotes)); |
4406 |
| - dumpComment(fout, query->data, tbinfo.oid); |
| 4392 | + if (!dataOnly) |
| 4393 | + { |
| 4394 | + /* Dump Sequence Comments */ |
4407 | 4395 |
|
| 4396 | + resetPQExpBuffer(query); |
| 4397 | + appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo.relname, force_quotes)); |
| 4398 | + dumpComment(fout, query->data, tbinfo.oid); |
| 4399 | + } |
4408 | 4400 | }
|
4409 | 4401 |
|
4410 | 4402 |
|
|
0 commit comments