diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-23 22:06:08 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-23 22:06:08 +0000 |
commit | f862c42009cd3e2e5f1ea78496148dfecab6d6a7 (patch) | |
tree | 4769e37ddd77623ab235486c9297fa8a9268d7f3 /src/bin/pg_dump/pg_dump.c | |
parent | 48b2802eeeaa3d0aca615726728c115c00073d5d (diff) | |
download | postgresql-f862c42009cd3e2e5f1ea78496148dfecab6d6a7.tar.gz |
Use dollar-quoting for function bodies, unless disabled with
--disable-dollar-quoting.
Andrew Dunstan
Diffstat (limited to 'src/bin/pg_dump/pg_dump.c')
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 2449a881bc..1721ea3ddd 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.368 2004/03/20 20:09:45 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.369 2004/03/23 22:06:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -107,6 +107,9 @@ static const CatalogId nilCatalogId = { 0, 0 }; static NamespaceInfo *g_namespaces; static int g_numNamespaces; +/* flag to turn on/off dollar quoting */ +static int disable_dollar_quoting = 0; + static void help(const char *progname); static NamespaceInfo *findNamespace(Oid nsoid, Oid objoid); @@ -231,8 +234,9 @@ main(int argc, char **argv) * the following options don't have an equivalent short option * letter, but are available as '-X long-name' */ - {"use-set-session-authorization", no_argument, &use_setsessauth, 1}, + {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1}, {"disable-triggers", no_argument, &disable_triggers, 1}, + {"use-set-session-authorization", no_argument, &use_setsessauth, 1}, {NULL, 0, NULL, 0} }; @@ -385,10 +389,12 @@ main(int argc, char **argv) * require arguments should use '-X feature=foo'. */ case 'X': - if (strcmp(optarg, "use-set-session-authorization") == 0) - /* no-op, still allowed for compatibility */ ; + if (strcmp(optarg, "disable-dollar-quoting") == 0) + disable_dollar_quoting = 1; else if (strcmp(optarg, "disable-triggers") == 0) disable_triggers = 1; + else if (strcmp(optarg, "use-set-session-authorization") == 0) + /* no-op, still allowed for compatibility */ ; else { fprintf(stderr, @@ -679,6 +685,8 @@ help(const char *progname) " plain text format\n")); printf(_(" -t, --table=TABLE dump the named table only\n")); printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n")); + printf(_(" -X disable-dollar-quoting, --disable-dollar-quoting\n" + " disable dollar quoting, use SQL standard quoting\n")); printf(_(" -X disable-triggers, --disable-triggers\n" " disable triggers during data-only restore\n")); @@ -5076,7 +5084,14 @@ dumpFunc(Archive *fout, FuncInfo *finfo) if (strcmp(prosrc, "-") != 0) { appendPQExpBuffer(asPart, ", "); - appendStringLiteral(asPart, prosrc, false); + /* + * where we have bin, use dollar quoting if allowed and src + * contains quote or backslash; else use regular quoting. + */ + if (disable_dollar_quoting) + appendStringLiteral(asPart, prosrc, false); + else + appendStringLiteralDQOpt(asPart, prosrc, false, NULL); } } else @@ -5084,7 +5099,11 @@ dumpFunc(Archive *fout, FuncInfo *finfo) if (strcmp(prosrc, "-") != 0) { appendPQExpBuffer(asPart, "AS "); - appendStringLiteral(asPart, prosrc, false); + /* with no bin, dollar quote src unconditionally if allowed */ + if (disable_dollar_quoting) + appendStringLiteral(asPart, prosrc, false); + else + appendStringLiteralDQ(asPart, prosrc, NULL); } } |