From 74b49a81294b2943179078272bc3413b33d16e6f Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 2 Jul 2005 17:01:59 +0000 Subject: Add E'' to internally created SQL strings that contain backslashes. Improve code clarity by using macros for E'' processing. --- src/backend/utils/adt/ruleutils.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index cbebd5495c0..0943c71f42a 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.202 2005/06/28 05:09:01 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.203 2005/07/02 17:01:50 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -564,12 +564,14 @@ pg_get_triggerdef(PG_FUNCTION_ARGS) { if (i > 0) appendStringInfo(&buf, ", "); + if (strchr(p, '\\') != NULL) + appendStringInfoChar(&buf, ESCAPE_STRING_SYNTAX); appendStringInfoChar(&buf, '\''); + while (*p) { - /* escape quotes and backslashes */ - if (*p == '\'' || *p == '\\') - appendStringInfoChar(&buf, '\\'); + if (SQL_STR_DOUBLE(*p)) + appendStringInfoChar(&buf, *p); appendStringInfoChar(&buf, *p++); } p++; @@ -3869,22 +3871,29 @@ get_const_expr(Const *constval, deparse_context *context) break; default: - /* * We must quote any funny characters in the constant's * representation. XXX Any MULTIBYTE considerations here? */ + for (valptr = extval; *valptr; valptr++) + if (*valptr == '\\' || + (unsigned char)*valptr < (unsigned char)' ') + { + appendStringInfoChar(buf, ESCAPE_STRING_SYNTAX); + break; + } + appendStringInfoChar(buf, '\''); for (valptr = extval; *valptr; valptr++) { char ch = *valptr; - if (ch == '\'' || ch == '\\') + if (SQL_STR_DOUBLE(ch)) { - appendStringInfoChar(buf, '\\'); + appendStringInfoChar(buf, ch); appendStringInfoChar(buf, ch); } - else if (((unsigned char) ch) < ((unsigned char) ' ')) + else if ((unsigned char)ch < (unsigned char)' ') appendStringInfo(buf, "\\%03o", (int) ch); else appendStringInfoChar(buf, ch); -- cgit v1.2.3