Skip to content

Commit 9b35ec2

Browse files
committed
Disable use of -o and -d pg_dump options together. Can't set oids in
inserts. Change some variables to bool to be clearer.
1 parent 9c56b40 commit 9b35ec2

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.109 1999/05/26 14:50:38 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.110 1999/05/26 16:06:45 momjian Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -112,12 +112,12 @@ FILE *g_fout; /* the script file */
112112
PGconn *g_conn; /* the database connection */
113113

114114
bool force_quotes; /* User wants to suppress double-quotes */
115-
int dumpData; /* dump data using proper insert strings */
116-
int attrNames; /* put attr names into insert strings */
117-
int schemaOnly;
118-
int dataOnly;
119-
int aclsOption;
120-
bool drop_schema;
115+
bool dumpData; /* dump data using proper insert strings */
116+
bool attrNames; /* put attr names into insert strings */
117+
bool schemaOnly;
118+
bool dataOnly;
119+
bool aclsOption;
120+
bool dropSchema;
121121

122122
char g_opaque_type[10]; /* name for the opaque type */
123123

@@ -233,7 +233,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
233233
bool copydone;
234234
char copybuf[COPYBUFSIZ];
235235

236-
if (oids)
236+
if (oids == true)
237237
{
238238
fprintf(fout, "COPY %s WITH OIDS FROM stdin;\n",
239239
fmtId(classname, force_quotes));
@@ -336,7 +336,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
336336
for (tuple = 0; tuple < PQntuples(res); tuple++)
337337
{
338338
fprintf(fout, "INSERT INTO %s ", fmtId(classname, force_quotes));
339-
if (attrNames)
339+
if (attrNames == true)
340340
{
341341
sprintf(q, "(");
342342
for (field = 0; field < PQnfields(res); field++)
@@ -545,7 +545,7 @@ main(int argc, char **argv)
545545
const char *pghost = NULL;
546546
const char *pgport = NULL;
547547
char *tablename = NULL;
548-
int oids = 0;
548+
bool oids = false;
549549
TableInfo *tblinfo;
550550
int numTables;
551551
char connect_string[512] = "";
@@ -556,13 +556,13 @@ main(int argc, char **argv)
556556

557557
g_verbose = false;
558558
force_quotes = true;
559-
drop_schema = false;
559+
dropSchema = false;
560560

561561
strcpy(g_comment_start, "-- ");
562562
g_comment_end[0] = '\0';
563563
strcpy(g_opaque_type, "opaque");
564564

565-
dataOnly = schemaOnly = dumpData = attrNames = 0;
565+
dataOnly = schemaOnly = dumpData = attrNames = false;
566566

567567
progname = *argv;
568568

@@ -571,19 +571,19 @@ main(int argc, char **argv)
571571
switch (c)
572572
{
573573
case 'a': /* Dump data only */
574-
dataOnly = 1;
574+
dataOnly = true;
575575
break;
576576
case 'c': /* clean (i.e., drop) schema prior to
577577
* create */
578-
drop_schema = true;
578+
dropSchema = true;
579579
break;
580580
case 'd': /* dump data as proper insert strings */
581-
dumpData = 1;
581+
dumpData = true;
582582
break;
583583
case 'D': /* dump data as proper insert strings with
584584
* attr names */
585-
dumpData = 1;
586-
attrNames = 1;
585+
dumpData = true;
586+
attrNames = true;
587587
break;
588588
case 'f': /* output file name */
589589
filename = optarg;
@@ -599,13 +599,13 @@ main(int argc, char **argv)
599599
force_quotes = true;
600600
break;
601601
case 'o': /* Dump oids */
602-
oids = 1;
602+
oids = true;
603603
break;
604604
case 'p': /* server port */
605605
pgport = optarg;
606606
break;
607607
case 's': /* dump schema only */
608-
schemaOnly = 1;
608+
schemaOnly = true;
609609
break;
610610
case 't': /* Dump data for this table only */
611611
{
@@ -637,7 +637,7 @@ main(int argc, char **argv)
637637
g_verbose = true;
638638
break;
639639
case 'z': /* Dump ACLs and table ownership info */
640-
aclsOption = 1;
640+
aclsOption = true;
641641
break;
642642
case 'u':
643643
use_password = 1;
@@ -648,6 +648,14 @@ main(int argc, char **argv)
648648
}
649649
}
650650

651+
if (dumpData == true && oids == true)
652+
{
653+
fprintf(stderr,
654+
"%s: INSERT's can not set oids, so INSERT and OID options can not be used together.\n",
655+
progname);
656+
exit(2);
657+
}
658+
651659
/* open the output file */
652660
if (filename == NULL)
653661
g_fout = stdout;
@@ -714,7 +722,7 @@ main(int argc, char **argv)
714722

715723
g_last_builtin_oid = findLastBuiltinOid();
716724

717-
if (oids)
725+
if (oids == true)
718726
setMaxOid(g_fout);
719727
if (!dataOnly)
720728
{
@@ -1663,7 +1671,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16631671

16641672
#if 0
16651673
/* XXX - how to emit this DROP TRIGGER? */
1666-
if (drop_schema)
1674+
if (dropSchema)
16671675
{
16681676
sprintf(query, "DROP TRIGGER %s ON %s;\n",
16691677
fmtId(PQgetvalue(res2, i2, i_tgname), force_quotes),
@@ -2067,7 +2075,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
20672075

20682076
becomeUser(fout, tinfo[i].usename);
20692077

2070-
if (drop_schema)
2078+
if (dropSchema)
20712079
{
20722080
sprintf(q, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes));
20732081
fputs(q, fout);
@@ -2170,7 +2178,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
21702178
lanname = checkForQuote(PQgetvalue(res, i, i_lanname));
21712179
lancompiler = checkForQuote(PQgetvalue(res, i, i_lancompiler));
21722180

2173-
if (drop_schema)
2181+
if (dropSchema)
21742182
fprintf(fout, "DROP PROCEDURAL LANGUAGE '%s';\n", lanname);
21752183

21762184
fprintf(fout, "CREATE %sPROCEDURAL LANGUAGE '%s' "
@@ -2288,7 +2296,7 @@ dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
22882296
PQclear(res);
22892297
}
22902298

2291-
if (drop_schema)
2299+
if (dropSchema)
22922300
{
22932301
sprintf(q, "DROP FUNCTION %s (", fmtId(finfo[i].proname, force_quotes));
22942302
for (j = 0; j < finfo[i].nargs; j++)
@@ -2415,7 +2423,7 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
24152423

24162424
becomeUser(fout, oprinfo[i].usename);
24172425

2418-
if (drop_schema)
2426+
if (dropSchema)
24192427
{
24202428
sprintf(q, "DROP OPERATOR %s (%s, %s);\n", oprinfo[i].oprname,
24212429
fmtId(findTypeByOid(tinfo, numTypes, oprinfo[i].oprleft), false),
@@ -2519,7 +2527,7 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
25192527

25202528
becomeUser(fout, agginfo[i].usename);
25212529

2522-
if (drop_schema)
2530+
if (dropSchema)
25232531
{
25242532
sprintf(q, "DROP AGGREGATE %s %s;\n", agginfo[i].aggname,
25252533
fmtId(findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype), false));
@@ -2739,7 +2747,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
27392747

27402748
becomeUser(fout, tblinfo[i].usename);
27412749

2742-
if (drop_schema)
2750+
if (dropSchema)
27432751
{
27442752
sprintf(q, "DROP TABLE %s;\n", fmtId(tblinfo[i].relname, force_quotes));
27452753
fputs(q, fout);
@@ -2979,7 +2987,7 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
29792987
strcpy(id1, fmtId(indinfo[i].indexrelname, force_quotes));
29802988
strcpy(id2, fmtId(indinfo[i].indrelname, force_quotes));
29812989

2982-
if (drop_schema)
2990+
if (dropSchema)
29832991
{
29842992
sprintf(q, "DROP INDEX %s;\n", id1);
29852993
fputs(q, fout);
@@ -3245,7 +3253,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
32453253

32463254
PQclear(res);
32473255

3248-
if (drop_schema)
3256+
if (dropSchema)
32493257
{
32503258
sprintf(query, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes));
32513259
fputs(query, fout);

0 commit comments

Comments
 (0)