mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Use E'' strings internally only when standard_conforming_strings =
'off'. This allows pg_dump output with standard_conforming_strings = 'on' to generate proper strings that can be loaded into other databases without the backslash doubling we typically do. I have added the dumping of the standard_conforming_strings value to pg_dump. I also added standard backslash handling for plpgsql.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.27 2006/04/30 21:15:33 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.28 2006/05/26 23:48:54 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -105,24 +105,29 @@ fmtId(const char *rawid)
|
||||
* Special characters are escaped. Quote mark ' goes to '' per SQL
|
||||
* standard, other stuff goes to \ sequences. If escapeAll is false,
|
||||
* whitespace characters are not escaped (tabs, newlines, etc.). This
|
||||
* is appropriate for dump file output.
|
||||
* is appropriate for dump file output. Using E'' strings for
|
||||
* backslashes is always safe for standard_conforming_strings on or off.
|
||||
*/
|
||||
void
|
||||
appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
|
||||
appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll,
|
||||
bool e_string_for_backslash)
|
||||
{
|
||||
char ch;
|
||||
const char *p;
|
||||
bool is_e_string = false;
|
||||
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
ch = *p;
|
||||
if (ch == '\\' ||
|
||||
|
||||
if ((e_string_for_backslash && ch == '\\') ||
|
||||
((unsigned char) ch < (unsigned char) ' ' &&
|
||||
(escapeAll ||
|
||||
(ch != '\t' && ch != '\n' && ch != '\v' &&
|
||||
ch != '\f' && ch != '\r'))))
|
||||
{
|
||||
appendPQExpBufferChar(buf, ESCAPE_STRING_SYNTAX);
|
||||
is_e_string = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -131,7 +136,7 @@ appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
ch = *p;
|
||||
if (SQL_STR_DOUBLE(ch))
|
||||
if (SQL_STR_DOUBLE(ch, is_e_string))
|
||||
{
|
||||
appendPQExpBufferChar(buf, ch);
|
||||
appendPQExpBufferChar(buf, ch);
|
||||
@ -208,7 +213,7 @@ appendStringLiteralDQOpt(PQExpBuffer buf, const char *str,
|
||||
bool escapeAll, const char *dqprefix)
|
||||
{
|
||||
if (strchr(str, '\'') == NULL && strchr(str, '\\') == NULL)
|
||||
appendStringLiteral(buf, str, escapeAll);
|
||||
appendStringLiteral(buf, str, escapeAll, true);
|
||||
else
|
||||
appendStringLiteralDQ(buf, str, dqprefix);
|
||||
}
|
||||
|
Reference in New Issue
Block a user