Use dollar-quoting for function bodies, unless disabled with
--disable-dollar-quoting. Andrew Dunstan
This commit is contained in:
parent
48b2802eee
commit
f862c42009
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.68 2003/12/01 22:07:58 momjian Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.69 2004/03/23 22:06:08 tgl Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -420,14 +420,12 @@ PostgreSQL documentation
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-X use-set-session-authorization</></term>
|
<term><option>-X disable-dollar-quoting</></term>
|
||||||
<term><option>--use-set-session-authorization</></term>
|
<term><option>--disable-dollar-quoting</></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
This option is obsolete but still accepted for backwards
|
This option disables the use of dollar quoting for function bodies,
|
||||||
compatibility.
|
and forces them to be quoted using SQL standard string syntax.
|
||||||
<application>pg_dump</application> now always behaves in the
|
|
||||||
way formerly selected by this option.
|
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -460,6 +458,19 @@ PostgreSQL documentation
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>-X use-set-session-authorization</></term>
|
||||||
|
<term><option>--use-set-session-authorization</></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
This option is obsolete but still accepted for backwards
|
||||||
|
compatibility.
|
||||||
|
<application>pg_dump</application> now always behaves in the
|
||||||
|
way formerly selected by this option.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-Z <replaceable class="parameter">0..9</replaceable></option></term>
|
<term><option>-Z <replaceable class="parameter">0..9</replaceable></option></term>
|
||||||
<term><option>--compress=<replaceable class="parameter">0..9</replaceable></option></term>
|
<term><option>--compress=<replaceable class="parameter">0..9</replaceable></option></term>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.11 2004/01/07 00:44:21 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.12 2004/03/23 22:06:08 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -142,6 +142,65 @@ appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string value to a dollar quoted literal and append it to
|
||||||
|
* the given buffer. If the dqprefix parameter is not NULL then the
|
||||||
|
* dollar quote delimiter will begin with that (after the opening $).
|
||||||
|
*
|
||||||
|
* No escaping is done at all on str, in compliance with the rules
|
||||||
|
* for parsing dollar quoted strings.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix)
|
||||||
|
{
|
||||||
|
static const char suffixes[] = "_XXXXXXX";
|
||||||
|
int nextchar = 0;
|
||||||
|
PQExpBuffer delimBuf = createPQExpBuffer();
|
||||||
|
|
||||||
|
/* start with $ + dqprefix if not NULL */
|
||||||
|
appendPQExpBufferChar(delimBuf, '$');
|
||||||
|
if (dqprefix)
|
||||||
|
appendPQExpBuffer(delimBuf, dqprefix);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make sure we choose a delimiter which (without the trailing $)
|
||||||
|
* is not present in the string being quoted. We don't check with the
|
||||||
|
* trailing $ because a string ending in $foo must not be quoted with
|
||||||
|
* $foo$.
|
||||||
|
*/
|
||||||
|
while (strstr(str, delimBuf->data) != NULL)
|
||||||
|
{
|
||||||
|
appendPQExpBufferChar(delimBuf, suffixes[nextchar++]);
|
||||||
|
nextchar %= sizeof(suffixes)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add trailing $ */
|
||||||
|
appendPQExpBufferChar(delimBuf, '$');
|
||||||
|
|
||||||
|
/* quote it and we are all done */
|
||||||
|
appendPQExpBufferStr(buf, delimBuf->data);
|
||||||
|
appendPQExpBufferStr(buf, str);
|
||||||
|
appendPQExpBufferStr(buf, delimBuf->data);
|
||||||
|
|
||||||
|
destroyPQExpBuffer(delimBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use dollar quoting if the string to be quoted contains ' or \,
|
||||||
|
* otherwise use standard quoting.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
appendStringLiteralDQOpt(PQExpBuffer buf, const char *str,
|
||||||
|
bool escapeAll, const char *dqprefix)
|
||||||
|
{
|
||||||
|
if (strchr(str, '\'') == NULL && strchr(str, '\\') == NULL)
|
||||||
|
appendStringLiteral(buf,str,escapeAll);
|
||||||
|
else
|
||||||
|
appendStringLiteralDQ(buf,str,dqprefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert backend's version string into a number.
|
* Convert backend's version string into a number.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.10 2004/01/07 00:44:21 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.h,v 1.11 2004/03/23 22:06:08 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +21,10 @@
|
||||||
extern const char *fmtId(const char *identifier);
|
extern const char *fmtId(const char *identifier);
|
||||||
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
|
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
|
||||||
bool escapeAll);
|
bool escapeAll);
|
||||||
|
extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
|
||||||
|
const char *dqprefix);
|
||||||
|
extern void appendStringLiteralDQOpt(PQExpBuffer buf, const char *str,
|
||||||
|
bool escapeAll, const char *dqprefix);
|
||||||
extern int parse_version(const char *versionString);
|
extern int parse_version(const char *versionString);
|
||||||
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
|
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
|
||||||
extern bool buildACLCommands(const char *name, const char *type,
|
extern bool buildACLCommands(const char *name, const char *type,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 NamespaceInfo *g_namespaces;
|
||||||
static int g_numNamespaces;
|
static int g_numNamespaces;
|
||||||
|
|
||||||
|
/* flag to turn on/off dollar quoting */
|
||||||
|
static int disable_dollar_quoting = 0;
|
||||||
|
|
||||||
|
|
||||||
static void help(const char *progname);
|
static void help(const char *progname);
|
||||||
static NamespaceInfo *findNamespace(Oid nsoid, Oid objoid);
|
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
|
* the following options don't have an equivalent short option
|
||||||
* letter, but are available as '-X long-name'
|
* 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},
|
{"disable-triggers", no_argument, &disable_triggers, 1},
|
||||||
|
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
|
||||||
|
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
@ -385,10 +389,12 @@ main(int argc, char **argv)
|
||||||
* require arguments should use '-X feature=foo'.
|
* require arguments should use '-X feature=foo'.
|
||||||
*/
|
*/
|
||||||
case 'X':
|
case 'X':
|
||||||
if (strcmp(optarg, "use-set-session-authorization") == 0)
|
if (strcmp(optarg, "disable-dollar-quoting") == 0)
|
||||||
/* no-op, still allowed for compatibility */ ;
|
disable_dollar_quoting = 1;
|
||||||
else if (strcmp(optarg, "disable-triggers") == 0)
|
else if (strcmp(optarg, "disable-triggers") == 0)
|
||||||
disable_triggers = 1;
|
disable_triggers = 1;
|
||||||
|
else if (strcmp(optarg, "use-set-session-authorization") == 0)
|
||||||
|
/* no-op, still allowed for compatibility */ ;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -679,6 +685,8 @@ help(const char *progname)
|
||||||
" plain text format\n"));
|
" plain text format\n"));
|
||||||
printf(_(" -t, --table=TABLE dump the named table only\n"));
|
printf(_(" -t, --table=TABLE dump the named table only\n"));
|
||||||
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\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"
|
printf(_(" -X disable-triggers, --disable-triggers\n"
|
||||||
" disable triggers during data-only restore\n"));
|
" disable triggers during data-only restore\n"));
|
||||||
|
|
||||||
|
@ -5076,7 +5084,14 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
|
||||||
if (strcmp(prosrc, "-") != 0)
|
if (strcmp(prosrc, "-") != 0)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(asPart, ", ");
|
appendPQExpBuffer(asPart, ", ");
|
||||||
|
/*
|
||||||
|
* 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);
|
appendStringLiteral(asPart, prosrc, false);
|
||||||
|
else
|
||||||
|
appendStringLiteralDQOpt(asPart, prosrc, false, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -5084,7 +5099,11 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
|
||||||
if (strcmp(prosrc, "-") != 0)
|
if (strcmp(prosrc, "-") != 0)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(asPart, "AS ");
|
appendPQExpBuffer(asPart, "AS ");
|
||||||
|
/* with no bin, dollar quote src unconditionally if allowed */
|
||||||
|
if (disable_dollar_quoting)
|
||||||
appendStringLiteral(asPart, prosrc, false);
|
appendStringLiteral(asPart, prosrc, false);
|
||||||
|
else
|
||||||
|
appendStringLiteralDQ(asPart, prosrc, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue