Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce495f8

Browse files
committed
- Dump relevant parts of sequences only when doing schemaOnly & dataOnly
- Prevent double-dumping of sequences when dataOnly.
1 parentaa28eeb commitce495f8

File tree

1 file changed

+39
-47
lines changed

1 file changed

+39
-47
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* 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 $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -106,6 +106,8 @@
106106
* - Fix help output: replace 'f' with 't' and change desc.
107107
* - Add extra arg to formatStringLiteral to specify how to handle LF & TAB.
108108
* 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.
109111
*
110112
*-------------------------------------------------------------------------
111113
*/
@@ -156,7 +158,7 @@ typedef enum _formatLiteralOptions {
156158
}formatLiteralOptions;
157159

158160
staticvoiddumpComment(Archive*outfile,constchar*target,constchar*oid);
159-
staticvoiddumpSequence(Archive*fout,TableInfotbinfo);
161+
staticvoiddumpSequence(Archive*fout,TableInfotbinfo,constboolschemaOnly,constbooldataOnly);
160162
staticvoiddumpACL(Archive*fout,TableInfotbinfo);
161163
staticvoiddumpTriggers(Archive*fout,constchar*tablename,
162164
TableInfo*tblinfo,intnumTables);
@@ -608,24 +610,6 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
608610
(onlytable==NULL|| (strlen(onlytable)==0)) ?"s" :"",
609611
g_comment_end);
610612

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-
629613
for (i=0;i<numTables;i++)
630614
{
631615
constchar*classname=tblinfo[i].relname;
@@ -3730,7 +3714,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
37303714
|| (serialSeq&& !strcmp(tblinfo[i].relname,serialSeq)))
37313715
{
37323716
/* becomeUser(fout, tblinfo[i].usename); */
3733-
dumpSequence(fout,tblinfo[i]);
3717+
dumpSequence(fout,tblinfo[i],schemaOnly,dataOnly);
37343718
if (!aclsSkip)
37353719
dumpACL(fout,tblinfo[i]);
37363720
}
@@ -4314,7 +4298,7 @@ findLastBuiltinOid(const char* dbname)
43144298

43154299

43164300
staticvoid
4317-
dumpSequence(Archive*fout,TableInfotbinfo)
4301+
dumpSequence(Archive*fout,TableInfotbinfo,constboolschemaOnly,constbooldataOnly)
43184302
{
43194303
PGresult*res;
43204304
int4last,
@@ -4367,44 +4351,52 @@ dumpSequence(Archive *fout, TableInfo tbinfo)
43674351
t=PQgetvalue(res,0,7);
43684352
called=*t;
43694353

4370-
PQclear(res);
4371-
4372-
resetPQExpBuffer(delqry);
4373-
appendPQExpBuffer(delqry,"DROP SEQUENCE %s;\n",fmtId(tbinfo.relname,force_quotes));
4374-
43754354
/*
43764355
* The logic we use for restoring sequences is as follows:
43774356
*- Add a basic CREATE SEQUENCE statement
43784357
*(use last_val for start if called == 'f', else use min_val for start_val).
43794358
*-Add a 'SETVAL(seq, last_val, iscalled)' at restore-time iff we load data
43804359
*/
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" :"");
43894360

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);
43924364

4365+
resetPQExpBuffer(delqry);
4366+
appendPQExpBuffer(delqry,"DROP SEQUENCE %s;\n",fmtId(tbinfo.relname,force_quotes));
43934367

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+
}
43984380

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);
44014387

4402-
/* Dump Sequence Comments */
4388+
ArchiveEntry(fout,tbinfo.oid,fmtId(tbinfo.relname,force_quotes),"SEQUENCE SET",NULL,
4389+
query->data,""/* Del */,"","",NULL,NULL);
4390+
}
44034391

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 */
44074395

4396+
resetPQExpBuffer(query);
4397+
appendPQExpBuffer(query,"SEQUENCE %s",fmtId(tbinfo.relname,force_quotes));
4398+
dumpComment(fout,query->data,tbinfo.oid);
4399+
}
44084400
}
44094401

44104402

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp