aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-05-28 21:13:54 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-05-28 21:13:54 +0000
commit134b463f027d1113df6f983c3348f165b1ac1ffa (patch)
tree7e247256f1fcb5e0e1a4759b854f673366c4478d /src/backend/utils/adt
parent117d73a9e7af61f6742e3d2b46f1dfbe3e02b9ca (diff)
downloadpostgresql-134b463f027d1113df6f983c3348f165b1ac1ffa.tar.gz
postgresql-134b463f027d1113df6f983c3348f165b1ac1ffa.zip
Fix up pg_dump to do string escaping fully correctly for client encoding
and standard_conforming_strings; likewise for the other client programs that need it. As per previous discussion, a pg_dump dump now conforms to the standard_conforming_strings setting of the source database. We don't use E'' syntax in the dump, thereby improving portability of the SQL. I added a SET escape_strings_warning = off command to keep the dumps from getting a lot of back-chatter from that.
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/quote.c27
-rw-r--r--src/backend/utils/adt/ruleutils.c48
2 files changed, 36 insertions, 39 deletions
diff --git a/src/backend/utils/adt/quote.c b/src/backend/utils/adt/quote.c
index 31991ee51ed..6da6c3df3d6 100644
--- a/src/backend/utils/adt/quote.c
+++ b/src/backend/utils/adt/quote.c
@@ -7,14 +7,13 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.19 2006/05/26 23:48:54 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.20 2006/05/28 21:13:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/builtins.h"
-#include "parser/gramparse.h"
/*
@@ -49,6 +48,12 @@ quote_ident(PG_FUNCTION_ARGS)
/*
* quote_literal -
* returns a properly quoted literal
+ *
+ * NOTE: think not to make this function's behavior change with
+ * standard_conforming_strings. We don't know where the result
+ * literal will be used, and so we must generate a result that
+ * will work with either setting. Take a look at what dblink
+ * uses this for before thinking you know better.
*/
Datum
quote_literal(PG_FUNCTION_ARGS)
@@ -66,20 +71,22 @@ quote_literal(PG_FUNCTION_ARGS)
cp1 = VARDATA(t);
cp2 = VARDATA(result);
- if (!standard_conforming_strings)
- for (; len-- > 0; cp1++)
- if (*cp1 == '\\')
- {
- *cp2++ = ESCAPE_STRING_SYNTAX;
- break;
- }
+ for (; len-- > 0; cp1++)
+ {
+ if (*cp1 == '\\')
+ {
+ *cp2++ = ESCAPE_STRING_SYNTAX;
+ break;
+ }
+ }
len = VARSIZE(t) - VARHDRSZ;
cp1 = VARDATA(t);
+
*cp2++ = '\'';
while (len-- > 0)
{
- if (SQL_STR_DOUBLE(*cp1, !standard_conforming_strings))
+ if (SQL_STR_DOUBLE(*cp1, true))
*cp2++ = *cp1;
*cp2++ = *cp1++;
}
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 8a06f7bcb66..83697436c0e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2,7 +2,7 @@
* ruleutils.c - Functions to convert stored expressions/querytrees
* back to source text
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.222 2006/05/26 23:48:54 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.223 2006/05/28 21:13:53 tgl Exp $
**********************************************************************/
#include "postgres.h"
@@ -534,18 +534,23 @@ pg_get_triggerdef(PG_FUNCTION_ARGS)
{
if (i > 0)
appendStringInfo(&buf, ", ");
- if (!standard_conforming_strings && strchr(p, '\\') != NULL)
- appendStringInfoChar(&buf, ESCAPE_STRING_SYNTAX);
+ /*
+ * We form the string literal according to the prevailing setting
+ * of standard_conforming_strings; we never use E''.
+ * User is responsible for making sure result is used correctly.
+ */
appendStringInfoChar(&buf, '\'');
-
while (*p)
{
- if (SQL_STR_DOUBLE(*p, !standard_conforming_strings))
- appendStringInfoChar(&buf, *p);
- appendStringInfoChar(&buf, *p++);
+ char ch = *p++;
+
+ if (SQL_STR_DOUBLE(ch, !standard_conforming_strings))
+ appendStringInfoChar(&buf, ch);
+ appendStringInfoChar(&buf, ch);
}
- p++;
appendStringInfoChar(&buf, '\'');
+ /* advance p to next string embedded in tgargs */
+ p++;
}
}
@@ -3883,8 +3888,7 @@ get_const_expr(Const *constval, deparse_context *context)
char *valptr;
bool isfloat = false;
bool needlabel;
- bool is_e_string = false;
-
+
if (constval->constisnull)
{
/*
@@ -3946,32 +3950,18 @@ get_const_expr(Const *constval, deparse_context *context)
default:
/*
- * We must quote any funny characters in the constant's
- * representation. XXX Any MULTIBYTE considerations here?
+ * We form the string literal according to the prevailing setting
+ * of standard_conforming_strings; we never use E''.
+ * User is responsible for making sure result is used correctly.
*/
- for (valptr = extval; *valptr; valptr++)
- if ((!standard_conforming_strings && *valptr == '\\') ||
- (unsigned char) *valptr < (unsigned char) ' ')
- {
- appendStringInfoChar(buf, ESCAPE_STRING_SYNTAX);
- is_e_string = true;
- break;
- }
-
appendStringInfoChar(buf, '\'');
for (valptr = extval; *valptr; valptr++)
{
char ch = *valptr;
- if (SQL_STR_DOUBLE(ch, is_e_string))
- {
- appendStringInfoChar(buf, ch);
- appendStringInfoChar(buf, ch);
- }
- else if ((unsigned char) ch < (unsigned char) ' ')
- appendStringInfo(buf, "\\%03o", (int) ch);
- else
+ if (SQL_STR_DOUBLE(ch, !standard_conforming_strings))
appendStringInfoChar(buf, ch);
+ appendStringInfoChar(buf, ch);
}
appendStringInfoChar(buf, '\'');
break;