diff options
author | Bruce Momjian <bruce@momjian.us> | 2005-07-02 17:01:59 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2005-07-02 17:01:59 +0000 |
commit | 74b49a81294b2943179078272bc3413b33d16e6f (patch) | |
tree | 1f610742e7fffbce204c4a95df8163d98bcaba6f /src/backend/utils/adt/ruleutils.c | |
parent | 654efe6aaa65d4bb53a3c888df1143558a1034ad (diff) | |
download | postgresql-74b49a81294b2943179078272bc3413b33d16e6f.tar.gz postgresql-74b49a81294b2943179078272bc3413b33d16e6f.zip |
Add E'' to internally created SQL strings that contain backslashes.
Improve code clarity by using macros for E'' processing.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 25 |
1 files changed, 17 insertions, 8 deletions
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); |