Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteaca117

Browse files
committed
Escape processing patch:
o turns off escape_string_warning in pg_dumpall.c o optionally use E'' for \password (undocumented option?) o honor standard_conforming-strings for \copy (but not support literal E'' strings) o optionally use E'' for \d commands o turn off escape_string_warning for createdb, createuser, droplang
1 parent751d985 commiteaca117

File tree

8 files changed

+54
-32
lines changed

8 files changed

+54
-32
lines changed

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.77 2006/05/28 21:13:54 tgl Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.78 2006/05/31 11:02:42 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -338,6 +338,8 @@ main(int argc, char *argv[])
338338
printf("SET client_encoding = '%s';\n",
339339
pg_encoding_to_char(encoding));
340340
printf("SET standard_conforming_strings = %s;\n",std_strings);
341+
if (strcmp(std_strings,"off")==0)
342+
printf("SET escape_string_warning = 'off';\n");
341343
printf("\n");
342344

343345
/* Dump roles (users) */

‎src/bin/psql/command.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.166 2006/04/02 20:08:22 neilc Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.167 2006/05/31 11:02:42 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -681,8 +681,9 @@ exec_command(const char *cmd,
681681
PGresult*res;
682682

683683
initPQExpBuffer(&buf);
684-
printfPQExpBuffer(&buf,"ALTER USER %s PASSWORD '%s';",
685-
fmtId(user),encrypted_password);
684+
printfPQExpBuffer(&buf,"ALTER USER %s PASSWORD %c'%s';",
685+
fmtId(user),NEED_E_STR(encrypted_password),
686+
encrypted_password);
686687
res=PSQLexec(buf.data, false);
687688
termPQExpBuffer(&buf);
688689
if (!res)

‎src/bin/psql/common.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.47 2006/03/06 19:49:20 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.48 2006/05/31 11:02:42 momjian Exp $
77
*/
88
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -22,6 +22,12 @@
2222

2323
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
2424

25+
/*
26+
*We use this to prefix strings with E'' that we know are already safe,
27+
*so we don't get an escape_string_warning.
28+
*/
29+
#defineNEED_E_STR(str)((strchr(str, '\\') && !standard_strings()) ? ESCAPE_STRING_SYNTAX : ' ')
30+
2531
/*
2632
* Safer versions of some standard C library functions. If an
2733
* out-of-memory condition occurs, these functions will bail out

‎src/bin/psql/copy.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.61 2006/05/26 19:51:29 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.62 2006/05/31 11:02:42 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"copy.h"
@@ -216,7 +216,7 @@ parse_slash_copy(const char *args)
216216
gotoerror;
217217

218218
token=strtokx(NULL,whitespace,NULL,"'",
219-
'\\', true,pset.encoding);
219+
standard_strings() ?0 :'\\', true,pset.encoding);
220220
if (!token)
221221
gotoerror;
222222

@@ -255,7 +255,7 @@ parse_slash_copy(const char *args)
255255
if (token&&pg_strcasecmp(token,"delimiters")==0)
256256
{
257257
token=strtokx(NULL,whitespace,NULL,"'",
258-
'\\', false,pset.encoding);
258+
standard_strings() ?0 :'\\', false,pset.encoding);
259259
if (!token)
260260
gotoerror;
261261
result->delim=pg_strdup(token);
@@ -290,10 +290,10 @@ parse_slash_copy(const char *args)
290290
elseif (pg_strcasecmp(token,"delimiter")==0)
291291
{
292292
token=strtokx(NULL,whitespace,NULL,"'",
293-
'\\', false,pset.encoding);
293+
standard_strings() ?0 :'\\', false,pset.encoding);
294294
if (token&&pg_strcasecmp(token,"as")==0)
295295
token=strtokx(NULL,whitespace,NULL,"'",
296-
'\\', false,pset.encoding);
296+
standard_strings() ?0 :'\\', false,pset.encoding);
297297
if (token)
298298
result->delim=pg_strdup(token);
299299
else
@@ -302,10 +302,10 @@ parse_slash_copy(const char *args)
302302
elseif (pg_strcasecmp(token,"null")==0)
303303
{
304304
token=strtokx(NULL,whitespace,NULL,"'",
305-
'\\', false,pset.encoding);
305+
standard_strings() ?0 :'\\', false,pset.encoding);
306306
if (token&&pg_strcasecmp(token,"as")==0)
307307
token=strtokx(NULL,whitespace,NULL,"'",
308-
'\\', false,pset.encoding);
308+
standard_strings() ?0 :'\\', false,pset.encoding);
309309
if (token)
310310
result->null=pg_strdup(token);
311311
else
@@ -314,10 +314,10 @@ parse_slash_copy(const char *args)
314314
elseif (pg_strcasecmp(token,"quote")==0)
315315
{
316316
token=strtokx(NULL,whitespace,NULL,"'",
317-
'\\', false,pset.encoding);
317+
standard_strings() ?0 :'\\', false,pset.encoding);
318318
if (token&&pg_strcasecmp(token,"as")==0)
319319
token=strtokx(NULL,whitespace,NULL,"'",
320-
'\\', false,pset.encoding);
320+
standard_strings() ?0 :'\\', false,pset.encoding);
321321
if (token)
322322
result->quote=pg_strdup(token);
323323
else
@@ -326,10 +326,10 @@ parse_slash_copy(const char *args)
326326
elseif (pg_strcasecmp(token,"escape")==0)
327327
{
328328
token=strtokx(NULL,whitespace,NULL,"'",
329-
'\\', false,pset.encoding);
329+
standard_strings() ?0 :'\\', false,pset.encoding);
330330
if (token&&pg_strcasecmp(token,"as")==0)
331331
token=strtokx(NULL,whitespace,NULL,"'",
332-
'\\', false,pset.encoding);
332+
standard_strings() ?0 :'\\', false,pset.encoding);
333333
if (token)
334334
result->escape=pg_strdup(token);
335335
else
@@ -462,20 +462,22 @@ do_copy(const char *args)
462462
if (options->delim)
463463
{
464464
if (options->delim[0]=='\'')
465-
appendPQExpBuffer(&query," USING DELIMITERS %s",
466-
options->delim);
465+
appendPQExpBuffer(&query," USING DELIMITERS %c%s",
466+
NEED_E_STR(options->delim),options->delim);
467467
else
468-
appendPQExpBuffer(&query," USING DELIMITERS '%s'",
469-
options->delim);
468+
appendPQExpBuffer(&query," USING DELIMITERS%c'%s'",
469+
NEED_E_STR(options->delim),options->delim);
470470
}
471471

472472
/* There is no backward-compatible CSV syntax */
473473
if (options->null)
474474
{
475475
if (options->null[0]=='\'')
476-
appendPQExpBuffer(&query," WITH NULL AS %s",options->null);
476+
appendPQExpBuffer(&query," WITH NULL AS %c%s",
477+
NEED_E_STR(options->null),options->null);
477478
else
478-
appendPQExpBuffer(&query," WITH NULL AS '%s'",options->null);
479+
appendPQExpBuffer(&query," WITH NULL AS %c'%s'",
480+
NEED_E_STR(options->null),options->null);
479481
}
480482

481483
if (options->csv_mode)
@@ -487,17 +489,21 @@ do_copy(const char *args)
487489
if (options->quote)
488490
{
489491
if (options->quote[0]=='\'')
490-
appendPQExpBuffer(&query," QUOTE AS %s",options->quote);
492+
appendPQExpBuffer(&query," QUOTE AS %c%s",
493+
NEED_E_STR(options->quote),options->quote);
491494
else
492-
appendPQExpBuffer(&query," QUOTE AS '%s'",options->quote);
495+
appendPQExpBuffer(&query," QUOTE AS %c'%s'",
496+
NEED_E_STR(options->quote),options->quote);
493497
}
494498

495499
if (options->escape)
496500
{
497501
if (options->escape[0]=='\'')
498-
appendPQExpBuffer(&query," ESCAPE AS %s",options->escape);
502+
appendPQExpBuffer(&query," ESCAPE AS %c%s",
503+
NEED_E_STR(options->escape),options->escape);
499504
else
500-
appendPQExpBuffer(&query," ESCAPE AS '%s'",options->escape);
505+
appendPQExpBuffer(&query," ESCAPE AS %c'%s'",
506+
NEED_E_STR(options->escape),options->escape);
501507
}
502508

503509
if (options->force_quote_list)

‎src/bin/psql/describe.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.137 2006/05/28 21:13:54 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.138 2006/05/31 11:02:42 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -1907,14 +1907,17 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
19071907
if (altnamevar)
19081908
{
19091909
appendPQExpBuffer(buf,"(%s ~ ",namevar);
1910+
appendPQExpBufferChar(buf,NEED_E_STR(namebuf.data));
19101911
appendStringLiteralConn(buf,namebuf.data,pset.db);
19111912
appendPQExpBuffer(buf,"\n OR %s ~ ",altnamevar);
1913+
appendPQExpBufferChar(buf,NEED_E_STR(namebuf.data));
19121914
appendStringLiteralConn(buf,namebuf.data,pset.db);
19131915
appendPQExpBuffer(buf,")\n");
19141916
}
19151917
else
19161918
{
19171919
appendPQExpBuffer(buf,"%s ~ ",namevar);
1920+
appendPQExpBufferChar(buf,NEED_E_STR(namebuf.data));
19181921
appendStringLiteralConn(buf,namebuf.data,pset.db);
19191922
appendPQExpBufferChar(buf,'\n');
19201923
}
@@ -1938,6 +1941,7 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
19381941
{
19391942
WHEREAND();
19401943
appendPQExpBuffer(buf,"%s ~ ",schemavar);
1944+
appendPQExpBufferChar(buf,NEED_E_STR(schemabuf.data));
19411945
appendStringLiteralConn(buf,schemabuf.data,pset.db);
19421946
appendPQExpBufferChar(buf,'\n');
19431947
}

‎src/bin/scripts/createdb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.19 2006/05/29 19:52:46 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.20 2006/05/31 11:02:42 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -185,6 +185,8 @@ main(int argc, char *argv[])
185185
{
186186
conn=connectDatabase(dbname,host,port,username,password,progname);
187187

188+
executeCommand(conn,"SET escape_string_warning TO 'off'",progname, false);
189+
188190
printfPQExpBuffer(&sql,"COMMENT ON DATABASE %s IS ",fmtId(dbname));
189191
appendStringLiteralConn(&sql,comment,conn);
190192
appendPQExpBuffer(&sql,";\n");

‎src/bin/scripts/createuser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.30 2006/05/29 19:52:46 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.31 2006/05/31 11:02:42 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -243,6 +243,8 @@ main(int argc, char *argv[])
243243
printfPQExpBuffer(&sql,"CREATE ROLE %s",fmtId(newuser));
244244
if (newpassword)
245245
{
246+
executeCommand(conn,"SET escape_string_warning TO 'off'",progname, false);
247+
246248
if (encrypted==TRI_YES)
247249
appendPQExpBuffer(&sql," ENCRYPTED");
248250
if (encrypted==TRI_NO)

‎src/bin/scripts/droplang.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.20 2006/05/29 19:52:46 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.21 2006/05/31 11:02:42 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -176,8 +176,7 @@ main(int argc, char *argv[])
176176
* Force schema search path to be just pg_catalog, so that we don't have
177177
* to be paranoid about search paths below.
178178
*/
179-
executeCommand(conn,"SET search_path = pg_catalog;",
180-
progname,echo);
179+
executeCommand(conn,"SET search_path = pg_catalog;",progname,echo);
181180

182181
/*
183182
* Make sure the language is installed and find the OIDs of the handler

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp