Skip to content

Commit 9601964

Browse files
author
Thomas G. Lockhart
committed
Surround all identifiers with double quotes.
Formerly did so only for those which clearly required it, but that would still miss things like reserved key words which also require it. Implement the "-n" switch to revert the double quote behavior to put DQs only where there is more than lower-case, digits, and underscores.
1 parent f93b697 commit 9601964

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/bin/pg_dump/common.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.25 1998/09/20 03:18:42 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.26 1998/10/02 16:43:38 thomas Exp $
1111
*
1212
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1313
*
@@ -486,18 +486,22 @@ findFuncByName(FuncInfo *finfo, int numFuncs, const char *name)
486486
*
487487
* checks input string for non-lowercase characters
488488
* returns pointer to input string or string surrounded by double quotes
489+
*
490+
* Note that the returned string should be used immediately since it
491+
* uses a static buffer to hold the string. Non-reentrant but fast.
489492
*/
490493
const char *
491494
fmtId(const char *rawid)
492495
{
493496
const char *cp;
494497
static char id[MAXQUERYLEN];
495498

496-
for (cp = rawid; *cp != '\0'; cp++)
497-
if (!(islower(*cp) || isdigit(*cp) || (*cp == '_')))
498-
break;
499+
if (! g_force_quotes)
500+
for (cp = rawid; *cp != '\0'; cp++)
501+
if (!(islower(*cp) || isdigit(*cp) || (*cp == '_')))
502+
break;
499503

500-
if (*cp != '\0')
504+
if (g_force_quotes || (*cp != '\0'))
501505
{
502506
strcpy(id, "\"");
503507
strcat(id, rawid);

src/bin/pg_dump/pg_dump.c

Lines changed: 10 additions & 3 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.87 1998/10/01 01:49:12 tgl Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.88 1998/10/02 16:43:40 thomas Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -100,6 +100,7 @@ extern int optind,
100100
opterr;
101101

102102
/* global decls */
103+
bool g_force_quotes; /* User wants to suppress double-quotes */
103104
bool g_verbose; /* User wants verbose narration of our
104105
* activities. */
105106
int g_last_builtin_oid; /* value of the last builtin oid */
@@ -128,11 +129,14 @@ usage(const char *progname)
128129
fprintf(stderr,
129130
"\t -d \t\t dump data as proper insert strings\n");
130131
fprintf(stderr,
131-
"\t -D \t\t dump data as inserts with attribute names\n");
132+
"\t -D \t\t dump data as inserts"
133+
" with attribute names\n");
132134
fprintf(stderr,
133135
"\t -f filename \t\t script output filename\n");
134136
fprintf(stderr,
135137
"\t -h hostname \t\t server host name\n");
138+
fprintf(stderr,
139+
"\t -n \t\t suppress most quotes around identifiers\n");
136140
fprintf(stderr,
137141
"\t -o \t\t dump object id's (oids)\n");
138142
fprintf(stderr,
@@ -552,7 +556,7 @@ main(int argc, char **argv)
552556

553557
progname = *argv;
554558

555-
while ((c = getopt(argc, argv, "adDf:h:op:st:vzu")) != EOF)
559+
while ((c = getopt(argc, argv, "adDf:h:nop:st:vzu")) != EOF)
556560
{
557561
switch (c)
558562
{
@@ -573,6 +577,9 @@ main(int argc, char **argv)
573577
case 'h': /* server host */
574578
pghost = optarg;
575579
break;
580+
case 'n': /* Do not force double-quotes on identifiers */
581+
g_force_quotes = false;
582+
break;
576583
case 'o': /* Dump oids */
577584
oids = 1;
578585
break;

src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pg_dump.h,v 1.32 1998/09/01 04:33:47 momjian Exp $
8+
* $Id: pg_dump.h,v 1.33 1998/10/02 16:43:41 thomas Exp $
99
*
1010
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1111
*
@@ -164,6 +164,7 @@ typedef struct _AclType
164164

165165

166166
/* global decls */
167+
extern bool g_force_quotes; /* double-quotes for identifiers flag */
167168
extern bool g_verbose; /* verbose flag */
168169
extern int g_last_builtin_oid; /* value of the last builtin oid */
169170
extern FILE *g_fout; /* the script file */

0 commit comments

Comments
 (0)