Commit 96019647 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

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.
parent f93b6974
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.25 1998/09/20 03:18:42 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.26 1998/10/02 16:43:38 thomas Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -486,6 +486,9 @@ findFuncByName(FuncInfo *finfo, int numFuncs, const char *name) ...@@ -486,6 +486,9 @@ findFuncByName(FuncInfo *finfo, int numFuncs, const char *name)
* *
* checks input string for non-lowercase characters * checks input string for non-lowercase characters
* returns pointer to input string or string surrounded by double quotes * returns pointer to input string or string surrounded by double quotes
*
* Note that the returned string should be used immediately since it
* uses a static buffer to hold the string. Non-reentrant but fast.
*/ */
const char * const char *
fmtId(const char *rawid) fmtId(const char *rawid)
...@@ -493,11 +496,12 @@ fmtId(const char *rawid) ...@@ -493,11 +496,12 @@ fmtId(const char *rawid)
const char *cp; const char *cp;
static char id[MAXQUERYLEN]; static char id[MAXQUERYLEN];
for (cp = rawid; *cp != '\0'; cp++) if (! g_force_quotes)
if (!(islower(*cp) || isdigit(*cp) || (*cp == '_'))) for (cp = rawid; *cp != '\0'; cp++)
break; if (!(islower(*cp) || isdigit(*cp) || (*cp == '_')))
break;
if (*cp != '\0') if (g_force_quotes || (*cp != '\0'))
{ {
strcpy(id, "\""); strcpy(id, "\"");
strcat(id, rawid); strcat(id, rawid);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.87 1998/10/01 01:49:12 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.88 1998/10/02 16:43:40 thomas Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -100,6 +100,7 @@ extern int optind, ...@@ -100,6 +100,7 @@ extern int optind,
opterr; opterr;
/* global decls */ /* global decls */
bool g_force_quotes; /* User wants to suppress double-quotes */
bool g_verbose; /* User wants verbose narration of our bool g_verbose; /* User wants verbose narration of our
* activities. */ * activities. */
int g_last_builtin_oid; /* value of the last builtin oid */ int g_last_builtin_oid; /* value of the last builtin oid */
...@@ -128,11 +129,14 @@ usage(const char *progname) ...@@ -128,11 +129,14 @@ usage(const char *progname)
fprintf(stderr, fprintf(stderr,
"\t -d \t\t dump data as proper insert strings\n"); "\t -d \t\t dump data as proper insert strings\n");
fprintf(stderr, fprintf(stderr,
"\t -D \t\t dump data as inserts with attribute names\n"); "\t -D \t\t dump data as inserts"
" with attribute names\n");
fprintf(stderr, fprintf(stderr,
"\t -f filename \t\t script output filename\n"); "\t -f filename \t\t script output filename\n");
fprintf(stderr, fprintf(stderr,
"\t -h hostname \t\t server host name\n"); "\t -h hostname \t\t server host name\n");
fprintf(stderr,
"\t -n \t\t suppress most quotes around identifiers\n");
fprintf(stderr, fprintf(stderr,
"\t -o \t\t dump object id's (oids)\n"); "\t -o \t\t dump object id's (oids)\n");
fprintf(stderr, fprintf(stderr,
...@@ -552,7 +556,7 @@ main(int argc, char **argv) ...@@ -552,7 +556,7 @@ main(int argc, char **argv)
progname = *argv; progname = *argv;
while ((c = getopt(argc, argv, "adDf:h:op:st:vzu")) != EOF) while ((c = getopt(argc, argv, "adDf:h:nop:st:vzu")) != EOF)
{ {
switch (c) switch (c)
{ {
...@@ -573,6 +577,9 @@ main(int argc, char **argv) ...@@ -573,6 +577,9 @@ main(int argc, char **argv)
case 'h': /* server host */ case 'h': /* server host */
pghost = optarg; pghost = optarg;
break; break;
case 'n': /* Do not force double-quotes on identifiers */
g_force_quotes = false;
break;
case 'o': /* Dump oids */ case 'o': /* Dump oids */
oids = 1; oids = 1;
break; break;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.32 1998/09/01 04:33:47 momjian Exp $ * $Id: pg_dump.h,v 1.33 1998/10/02 16:43:41 thomas Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -164,6 +164,7 @@ typedef struct _AclType ...@@ -164,6 +164,7 @@ typedef struct _AclType
/* global decls */ /* global decls */
extern bool g_force_quotes; /* double-quotes for identifiers flag */
extern bool g_verbose; /* verbose flag */ extern bool g_verbose; /* verbose flag */
extern int g_last_builtin_oid; /* value of the last builtin oid */ extern int g_last_builtin_oid; /* value of the last builtin oid */
extern FILE *g_fout; /* the script file */ extern FILE *g_fout; /* the script file */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment