7
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
- * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.17 2005/04/30 08:08:51 neilc Exp $
10
+ * $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.18 2005/07/01 21:03:25 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -111,6 +111,27 @@ fmtId(const char *rawid)
111
111
void
112
112
appendStringLiteral (PQExpBuffer buf , const char * str , bool escapeAll )
113
113
{
114
+ bool has_escapes = false;
115
+ const char * str2 = str ;
116
+
117
+ while (* str2 )
118
+ {
119
+ char ch = * str2 ++ ;
120
+
121
+ if (ch == '\\' ||
122
+ ((unsigned char ) ch < (unsigned char ) ' ' &&
123
+ (escapeAll ||
124
+ (ch != '\t' && ch != '\n' && ch != '\v' &&
125
+ ch != '\f' && ch != '\r' ))))
126
+ {
127
+ has_escapes = true;
128
+ break ;
129
+ }
130
+ }
131
+
132
+ if (has_escapes )
133
+ appendPQExpBufferChar (buf , 'E' );
134
+
114
135
appendPQExpBufferChar (buf , '\'' );
115
136
while (* str )
116
137
{
@@ -122,9 +143,9 @@ appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
122
143
appendPQExpBufferChar (buf , ch );
123
144
}
124
145
else if ((unsigned char ) ch < (unsigned char ) ' ' &&
125
- (escapeAll
126
- || (ch != '\t' && ch != '\n' && ch != '\v' && ch != '\f' && ch != '\r' )
127
- ))
146
+ (escapeAll ||
147
+ (ch != '\t' && ch != '\n' && ch != '\v' &&
148
+ ch != '\f' && ch != '\r' ) ))
128
149
{
129
150
/*
130
151
* generate octal escape for control chars other than
0 commit comments