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

Commit6178762

Browse files
committed
Fix up hack to suppress escape_string_warning so that it actually works
and there's only one place that's a kluge, ie, appendStringLiteralConn.Note that pg_dump itself doesn't use appendStringLiteralConn, so itsbehavior is not affected; only the other utility programs care.
1 parent2703007 commit6178762

File tree

7 files changed

+61
-50
lines changed

7 files changed

+61
-50
lines changed

‎src/bin/pg_dump/dumputils.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.29 2006/05/28 21:13:54 tgl Exp $
10+
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.30 2006/06/01 00:15:36 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -191,6 +191,21 @@ appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
191191
{
192192
size_tlength=strlen(str);
193193

194+
/*
195+
* XXX This is a kluge to silence escape_string_warning in our utility
196+
* programs. It should go away someday.
197+
*/
198+
if (strchr(str,'\\')!=NULL&&PQserverVersion(conn) >=80100)
199+
{
200+
/* ensure we are not adjacent to an identifier */
201+
if (buf->len>0&&buf->data[buf->len-1]!=' ')
202+
appendPQExpBufferChar(buf,' ');
203+
appendPQExpBufferChar(buf,ESCAPE_STRING_SYNTAX);
204+
appendStringLiteral(buf,str,PQclientEncoding(conn), false);
205+
return;
206+
}
207+
/* XXX end kluge */
208+
194209
if (!enlargePQExpBuffer(buf,2*length+2))
195210
return;
196211
appendPQExpBufferChar(buf,'\'');

‎src/bin/psql/command.c

Lines changed: 4 additions & 4 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.167 2006/05/31 11:02:42 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.168 2006/06/01 00:15:36 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -681,9 +681,9 @@ exec_command(const char *cmd,
681681
PGresult*res;
682682

683683
initPQExpBuffer(&buf);
684-
printfPQExpBuffer(&buf,"ALTER USER %s PASSWORD%c'%s';",
685-
fmtId(user),NEED_E_STR(encrypted_password),
686-
encrypted_password);
684+
printfPQExpBuffer(&buf,"ALTER USER %s PASSWORD ",
685+
fmtId(user));
686+
appendStringLiteralConn(&buf,encrypted_password,pset.db);
687687
res=PSQLexec(buf.data, false);
688688
termPQExpBuffer(&buf);
689689
if (!res)

‎src/bin/psql/common.h

Lines changed: 1 addition & 7 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/common.h,v 1.48 2006/05/31 11:02:42 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.49 2006/06/01 00:15:36 tgl Exp $
77
*/
88
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -22,12 +22,6 @@
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-
3125
/*
3226
* Safer versions of some standard C library functions. If an
3327
* out-of-memory condition occurs, these functions will bail out

‎src/bin/psql/copy.c

Lines changed: 37 additions & 27 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.62 2006/05/31 11:02:42 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.63 2006/06/01 00:15:36 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"copy.h"
@@ -19,6 +19,7 @@
1919
#include"libpq-fe.h"
2020
#include"pqexpbuffer.h"
2121
#include"pqsignal.h"
22+
#include"dumputils.h"
2223

2324
#include"settings.h"
2425
#include"common.h"
@@ -113,6 +114,7 @@ parse_slash_copy(const char *args)
113114
char*line;
114115
char*token;
115116
constchar*whitespace=" \t\n\r";
117+
charnonstd_backslash=standard_strings() ?0 :'\\';
116118

117119
if (args)
118120
line=pg_strdup(args);
@@ -216,7 +218,7 @@ parse_slash_copy(const char *args)
216218
gotoerror;
217219

218220
token=strtokx(NULL,whitespace,NULL,"'",
219-
standard_strings() ?0 :'\\', true,pset.encoding);
221+
nonstd_backslash, true,pset.encoding);
220222
if (!token)
221223
gotoerror;
222224

@@ -255,7 +257,7 @@ parse_slash_copy(const char *args)
255257
if (token&&pg_strcasecmp(token,"delimiters")==0)
256258
{
257259
token=strtokx(NULL,whitespace,NULL,"'",
258-
standard_strings() ?0 :'\\', false,pset.encoding);
260+
nonstd_backslash, false,pset.encoding);
259261
if (!token)
260262
gotoerror;
261263
result->delim=pg_strdup(token);
@@ -290,10 +292,10 @@ parse_slash_copy(const char *args)
290292
elseif (pg_strcasecmp(token,"delimiter")==0)
291293
{
292294
token=strtokx(NULL,whitespace,NULL,"'",
293-
standard_strings() ?0 :'\\', false,pset.encoding);
295+
nonstd_backslash, false,pset.encoding);
294296
if (token&&pg_strcasecmp(token,"as")==0)
295297
token=strtokx(NULL,whitespace,NULL,"'",
296-
standard_strings() ?0 :'\\', false,pset.encoding);
298+
nonstd_backslash, false,pset.encoding);
297299
if (token)
298300
result->delim=pg_strdup(token);
299301
else
@@ -302,10 +304,10 @@ parse_slash_copy(const char *args)
302304
elseif (pg_strcasecmp(token,"null")==0)
303305
{
304306
token=strtokx(NULL,whitespace,NULL,"'",
305-
standard_strings() ?0 :'\\', false,pset.encoding);
307+
nonstd_backslash, false,pset.encoding);
306308
if (token&&pg_strcasecmp(token,"as")==0)
307309
token=strtokx(NULL,whitespace,NULL,"'",
308-
standard_strings() ?0 :'\\', false,pset.encoding);
310+
nonstd_backslash, false,pset.encoding);
309311
if (token)
310312
result->null=pg_strdup(token);
311313
else
@@ -314,10 +316,10 @@ parse_slash_copy(const char *args)
314316
elseif (pg_strcasecmp(token,"quote")==0)
315317
{
316318
token=strtokx(NULL,whitespace,NULL,"'",
317-
standard_strings() ?0 :'\\', false,pset.encoding);
319+
nonstd_backslash, false,pset.encoding);
318320
if (token&&pg_strcasecmp(token,"as")==0)
319321
token=strtokx(NULL,whitespace,NULL,"'",
320-
standard_strings() ?0 :'\\', false,pset.encoding);
322+
nonstd_backslash, false,pset.encoding);
321323
if (token)
322324
result->quote=pg_strdup(token);
323325
else
@@ -326,10 +328,10 @@ parse_slash_copy(const char *args)
326328
elseif (pg_strcasecmp(token,"escape")==0)
327329
{
328330
token=strtokx(NULL,whitespace,NULL,"'",
329-
standard_strings() ?0 :'\\', false,pset.encoding);
331+
nonstd_backslash, false,pset.encoding);
330332
if (token&&pg_strcasecmp(token,"as")==0)
331333
token=strtokx(NULL,whitespace,NULL,"'",
332-
standard_strings() ?0 :'\\', false,pset.encoding);
334+
nonstd_backslash, false,pset.encoding);
333335
if (token)
334336
result->escape=pg_strdup(token);
335337
else
@@ -461,23 +463,27 @@ do_copy(const char *args)
461463
/* Uses old COPY syntax for backward compatibility 2002-06-19 */
462464
if (options->delim)
463465
{
466+
/* if user gave a quoted string, use it as-is */
464467
if (options->delim[0]=='\'')
465-
appendPQExpBuffer(&query," USING DELIMITERS %c%s",
466-
NEED_E_STR(options->delim),options->delim);
468+
appendPQExpBuffer(&query," USING DELIMITERS %s",options->delim);
467469
else
468-
appendPQExpBuffer(&query," USING DELIMITERS %c'%s'",
469-
NEED_E_STR(options->delim),options->delim);
470+
{
471+
appendPQExpBuffer(&query," USING DELIMITERS ");
472+
appendStringLiteralConn(&query,options->delim,pset.db);
473+
}
470474
}
471475

472476
/* There is no backward-compatible CSV syntax */
473477
if (options->null)
474478
{
479+
/* if user gave a quoted string, use it as-is */
475480
if (options->null[0]=='\'')
476-
appendPQExpBuffer(&query," WITH NULL AS %c%s",
477-
NEED_E_STR(options->null),options->null);
481+
appendPQExpBuffer(&query," WITH NULL AS %s",options->null);
478482
else
479-
appendPQExpBuffer(&query," WITH NULL AS %c'%s'",
480-
NEED_E_STR(options->null),options->null);
483+
{
484+
appendPQExpBuffer(&query," WITH NULL AS ");
485+
appendStringLiteralConn(&query,options->null,pset.db);
486+
}
481487
}
482488

483489
if (options->csv_mode)
@@ -488,22 +494,26 @@ do_copy(const char *args)
488494

489495
if (options->quote)
490496
{
497+
/* if user gave a quoted string, use it as-is */
491498
if (options->quote[0]=='\'')
492-
appendPQExpBuffer(&query," QUOTE AS %c%s",
493-
NEED_E_STR(options->quote),options->quote);
499+
appendPQExpBuffer(&query," QUOTE AS %s",options->quote);
494500
else
495-
appendPQExpBuffer(&query," QUOTE AS %c'%s'",
496-
NEED_E_STR(options->quote),options->quote);
501+
{
502+
appendPQExpBuffer(&query," QUOTE AS ");
503+
appendStringLiteralConn(&query,options->quote,pset.db);
504+
}
497505
}
498506

499507
if (options->escape)
500508
{
509+
/* if user gave a quoted string, use it as-is */
501510
if (options->escape[0]=='\'')
502-
appendPQExpBuffer(&query," ESCAPE AS %c%s",
503-
NEED_E_STR(options->escape),options->escape);
511+
appendPQExpBuffer(&query," ESCAPE AS %s",options->escape);
504512
else
505-
appendPQExpBuffer(&query," ESCAPE AS %c'%s'",
506-
NEED_E_STR(options->escape),options->escape);
513+
{
514+
appendPQExpBuffer(&query," ESCAPE AS ");
515+
appendStringLiteralConn(&query,options->escape,pset.db);
516+
}
507517
}
508518

509519
if (options->force_quote_list)

‎src/bin/psql/describe.c

Lines changed: 1 addition & 5 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/describe.c,v 1.138 2006/05/31 11:02:42 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.139 2006/06/01 00:15:36 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -1907,17 +1907,14 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
19071907
if (altnamevar)
19081908
{
19091909
appendPQExpBuffer(buf,"(%s ~ ",namevar);
1910-
appendPQExpBufferChar(buf,NEED_E_STR(namebuf.data));
19111910
appendStringLiteralConn(buf,namebuf.data,pset.db);
19121911
appendPQExpBuffer(buf,"\n OR %s ~ ",altnamevar);
1913-
appendPQExpBufferChar(buf,NEED_E_STR(namebuf.data));
19141912
appendStringLiteralConn(buf,namebuf.data,pset.db);
19151913
appendPQExpBuffer(buf,")\n");
19161914
}
19171915
else
19181916
{
19191917
appendPQExpBuffer(buf,"%s ~ ",namevar);
1920-
appendPQExpBufferChar(buf,NEED_E_STR(namebuf.data));
19211918
appendStringLiteralConn(buf,namebuf.data,pset.db);
19221919
appendPQExpBufferChar(buf,'\n');
19231920
}
@@ -1941,7 +1938,6 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
19411938
{
19421939
WHEREAND();
19431940
appendPQExpBuffer(buf,"%s ~ ",schemavar);
1944-
appendPQExpBufferChar(buf,NEED_E_STR(schemabuf.data));
19451941
appendStringLiteralConn(buf,schemabuf.data,pset.db);
19461942
appendPQExpBufferChar(buf,'\n');
19471943
}

‎src/bin/scripts/createdb.c

Lines changed: 1 addition & 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/createdb.c,v 1.20 2006/05/31 11:02:42 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.21 2006/06/01 00:15:36 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -185,8 +185,6 @@ 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-
190188
printfPQExpBuffer(&sql,"COMMENT ON DATABASE %s IS ",fmtId(dbname));
191189
appendStringLiteralConn(&sql,comment,conn);
192190
appendPQExpBuffer(&sql,";\n");

‎src/bin/scripts/createuser.c

Lines changed: 1 addition & 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/createuser.c,v 1.31 2006/05/31 11:02:42 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.32 2006/06/01 00:15:36 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -243,8 +243,6 @@ 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-
248246
if (encrypted==TRI_YES)
249247
appendPQExpBuffer(&sql," ENCRYPTED");
250248
if (encrypted==TRI_NO)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp