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

Commit19c21d1

Browse files
committed
Enable standard_conforming_strings to be turned on.
Kevin Grittner
1 parenta9c1047 commit19c21d1

File tree

11 files changed

+294
-112
lines changed

11 files changed

+294
-112
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.49 2006/03/04 22:19:31 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.50 2006/03/0619:49:19 momjian Exp $
33
-->
44
<chapter Id="runtime-config">
55
<title>Server Configuration</title>
@@ -3737,10 +3737,28 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
37373737
</para>
37383738
<para>
37393739
Escape string syntax (<literal>E'...'</>) should be used for
3740-
escapes, because in future versions of
3741-
<productname>PostgreSQL</productname> ordinary strings will have
3740+
backslash escape sequences, because ordinary strings have
37423741
the standard-conforming behavior of treating backslashes
3743-
literally.
3742+
literally when the <literal>standard-conforming-strings</>
3743+
option is set <literal>on</>.
3744+
</para>
3745+
</listitem>
3746+
</varlistentry>
3747+
3748+
<varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings">
3749+
<term><varname>standard_conforming_strings</varname> (<type>boolean</type>)</term>
3750+
<indexterm><primary>strings</><secondary>escape</></>
3751+
<indexterm>
3752+
<primary><varname>standard_conforming_strings</> configuration parameter</primary>
3753+
</indexterm>
3754+
<listitem>
3755+
<para>
3756+
Controls whether ordinary string literals
3757+
(<literal>'...'</>) treat backslashes literally, as specified in
3758+
the SQL standard. Applications may check this
3759+
parameter to determine how string literals will be processed.
3760+
The presence of this parameter can also be taken as an indication
3761+
that the escape string syntax (<literal>E'...'</>) is supported.
37443762
</para>
37453763
</listitem>
37463764
</varlistentry>
@@ -3992,28 +4010,6 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
39924010
</listitem>
39934011
</varlistentry>
39944012

3995-
<varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings">
3996-
<term><varname>standard_conforming_strings</varname> (<type>boolean</type>)</term>
3997-
<indexterm><primary>strings</><secondary>escape</></>
3998-
<indexterm>
3999-
<primary><varname>standard_conforming_strings</> configuration parameter</primary>
4000-
</indexterm>
4001-
<listitem>
4002-
<para>
4003-
Reports whether ordinary string literals
4004-
(<literal>'...'</>) treat backslashes literally, as specified in
4005-
the SQL standard. The value is currently always <literal>off</>,
4006-
indicating that backslashes are treated as escapes. It is planned
4007-
that this will change to <literal>on</> in a future
4008-
<productname>PostgreSQL</productname> release when string literal
4009-
syntax changes to meet the standard. Applications may check this
4010-
parameter to determine how string literals will be processed.
4011-
The presence of this parameter can also be taken as an indication
4012-
that the escape string syntax (<literal>E'...'</>) is supported.
4013-
</para>
4014-
</listitem>
4015-
</varlistentry>
4016-
40174013
</variablelist>
40184014
</sect1>
40194015

‎src/backend/parser/scan.l

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
2626
* IDENTIFICATION
27-
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.130 2006/03/05 15:58:34 momjian Exp $
27+
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.131 2006/03/06 19:49:20 momjian Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -51,13 +51,14 @@ static intxcdepth = 0;/* depth of nesting in slash-star comments */
5151
staticchar *dolqstart;/* current $foo$ quote start string*/
5252

5353
/*
54-
* GUCvariable. This is a DIRECT violation of the warning given at the
54+
* GUCvariables. This is a DIRECT violation of the warning given at the
5555
* head of gram.y, ie flex/bison code must not depend on any GUC variables;
5656
* as such, changing its value can induce very unintuitive behavior.
5757
* But we shall have to live with it as a short-term thing until the switch
5858
* to SQL-standard string syntax is complete.
5959
*/
6060
boolescape_string_warning;
61+
boolstandard_conforming_strings;
6162

6263
staticboolwarn_on_first_escape;
6364

@@ -77,6 +78,7 @@ static void addlitchar(unsigned char ychar);
7778
staticchar *litbufdup(void);
7879
staticintpg_err_position(void);
7980
staticvoidcheck_escape_warning(void);
81+
staticvoidcheck_string_escape_warning(unsignedchar ychar);
8082

8183
/*
8284
* When we parse a token that requires multiple lexer rules to process,
@@ -119,14 +121,16 @@ static unsigned char unescape_single_char(unsigned char c);
119121
* <xc> extended C-style comments
120122
* <xd> delimited identifiers (double-quoted identifiers)
121123
* <xh> hexadecimal numeric string
122-
* <xq> quoted strings
124+
* <xq> standard quoted strings
125+
* <xe> extended quoted strings (support backslash escape sequences)
123126
* <xdolq> $foo$ quoted strings
124127
*/
125128

126129
%xxb
127130
%xxc
128131
%xxd
129132
%xxh
133+
%xxe
130134
%xxq
131135
%xxdolq
132136

@@ -200,16 +204,18 @@ xnstart[nN]{quote}
200204

201205
/* Quoted string that allows backslash escapes */
202206
xestart[eE]{quote}
207+
xeinside[^\\']+
208+
xeescape[\\][^0-7]
209+
xeoctesc[\\][0-7]{1,3}
210+
xehexesc[\\]x[0-9A-Fa-f]{1,2}
203211

204212
/* Extended quote
205213
* xqdouble implements embedded quote, ''''
206214
*/
207215
xqstart{quote}
208216
xqdouble{quote}{quote}
209217
xqinside[^\\']+
210-
xqescape[\\][^0-7]
211-
xqoctesc[\\][0-7]{1,3}
212-
xqhexesc[\\]x[0-9A-Fa-f]{1,2}
218+
xqbackslash[\\]
213219

214220
/* $foo$ style quotes ("dollar quoting")
215221
* The quoted string starts with $foo$ where "foo" is an optional string
@@ -428,73 +434,62 @@ other.
428434
{xqstart}{
429435
warn_on_first_escape =true;
430436
token_start = yytext;
431-
BEGIN(xq);
437+
if (standard_conforming_strings)
438+
BEGIN(xq);
439+
else
440+
BEGIN(xe);
432441
startlit();
433442
}
434443
{xestart}{
435444
warn_on_first_escape =false;
436445
token_start = yytext;
437-
BEGIN(xq);
446+
BEGIN(xe);
438447
startlit();
439448
}
440-
<xq>{quotestop}|
441-
<xq>{quotefail} {
449+
<xq,xe>{quotestop}|
450+
<xq,xe>{quotefail} {
442451
yyless(1);
443452
BEGIN(INITIAL);
444453
yylval.str =litbufdup();
445454
return SCONST;
446455
}
447-
<xq>{xqdouble} {
456+
<xq,xe>{xqdouble} {
448457
addlitchar('\'');
449458
}
450459
<xq>{xqinside} {
451460
addlit(yytext, yyleng);
452461
}
453-
<xq>{xqescape} {
454-
if (yytext[1] =='\'')
455-
{
456-
if (warn_on_first_escape && escape_string_warning)
457-
ereport(WARNING,
458-
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
459-
errmsg("nonstandard use of\\' in a string literal"),
460-
errhint("Use '' to write quotes in strings, or use the escape string syntax (E'...')."),
461-
errposition(pg_err_position())));
462-
warn_on_first_escape =false;/* warn only once per string */
463-
}
464-
elseif (yytext[1] =='\\')
465-
{
466-
if (warn_on_first_escape && escape_string_warning)
467-
ereport(WARNING,
468-
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
469-
errmsg("nonstandard use of\\\\ in a string literal"),
470-
errhint("Use the escape string syntax for backslashes, e.g., E'\\\\'."),
471-
errposition(pg_err_position())));
472-
warn_on_first_escape =false;/* warn only once per string */
473-
}
474-
else
475-
check_escape_warning();
462+
<xe>{xeinside} {
463+
addlit(yytext, yyleng);
464+
}
465+
<xq>{xqbackslash} {
466+
check_string_escape_warning(yytext[1]);
467+
addlitchar('\\');
468+
}
469+
<xe>{xeescape} {
470+
check_string_escape_warning(yytext[1]);
476471
addlitchar(unescape_single_char(yytext[1]));
477472
}
478-
<xq>{xqoctesc} {
473+
<xe>{xeoctesc} {
479474
unsignedchar c =strtoul(yytext+1,NULL,8);
480475

481476
check_escape_warning();
482477
addlitchar(c);
483478
}
484-
<xq>{xqhexesc} {
479+
<xe>{xehexesc} {
485480
unsignedchar c =strtoul(yytext+2,NULL,16);
486481

487482
check_escape_warning();
488483
addlitchar(c);
489484
}
490-
<xq>{quotecontinue} {
485+
<xq,xe>{quotecontinue} {
491486
/* ignore */
492487
}
493-
<xq>.{
488+
<xe>.{
494489
/* This is only needed for \ just before EOF */
495490
addlitchar(yytext[0]);
496491
}
497-
<xq><<EOF>>{yyerror("unterminated quoted string"); }
492+
<xq,xe><<EOF>>{yyerror("unterminated quoted string"); }
498493

499494
{dolqdelim}{
500495
token_start = yytext;
@@ -875,6 +870,33 @@ unescape_single_char(unsigned char c)
875870
}
876871
}
877872

873+
staticvoid
874+
check_string_escape_warning(unsignedchar ychar)
875+
{
876+
if (ychar =='\'')
877+
{
878+
if (warn_on_first_escape && escape_string_warning)
879+
ereport(WARNING,
880+
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
881+
errmsg("nonstandard use of\\' in a string literal"),
882+
errhint("Use '' to write quotes in strings, or use the escape string syntax (E'...')."),
883+
errposition(pg_err_position())));
884+
warn_on_first_escape =false;/* warn only once per string */
885+
}
886+
elseif (ychar =='\\')
887+
{
888+
if (warn_on_first_escape && escape_string_warning)
889+
ereport(WARNING,
890+
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
891+
errmsg("nonstandard use of\\\\ in a string literal"),
892+
errhint("Use the escape string syntax for backslashes, e.g., E'\\\\'."),
893+
errposition(pg_err_position())));
894+
warn_on_first_escape =false;/* warn only once per string */
895+
}
896+
else
897+
check_escape_warning();
898+
}
899+
878900
staticvoid
879901
check_escape_warning(void)
880902
{

‎src/backend/utils/misc/guc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.312 2006/03/05 15:58:49 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.313 2006/03/06 19:49:20 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -224,7 +224,6 @@ static intmax_index_keys;
224224
staticintmax_identifier_length;
225225
staticintblock_size;
226226
staticboolinteger_datetimes;
227-
staticboolstandard_conforming_strings;
228227

229228
/* should be static, but commands/variable.c needs to get at these */
230229
char*role_string;
@@ -974,10 +973,10 @@ static struct config_bool ConfigureNamesBool[] =
974973
},
975974

976975
{
977-
{"standard_conforming_strings",PGC_INTERNAL,PRESET_OPTIONS,
976+
{"standard_conforming_strings",PGC_USERSET,COMPAT_OPTIONS_PREVIOUS,
978977
gettext_noop("'...' strings treat backslashes literally."),
979978
NULL,
980-
GUC_REPORT |GUC_NOT_IN_SAMPLE |GUC_DISALLOW_IN_FILE
979+
GUC_REPORT
981980
},
982981
&standard_conforming_strings,
983982
false,NULL,NULL

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@
415415
#add_missing_from = off
416416
#array_nulls = on
417417
#default_with_oids = off
418-
#escape_string_warning = off
418+
#escape_string_warning = off# warn about backslashes in string literals
419+
#standard_conforming_strings = off# SQL standard string literal processing
419420
#regex_flavor = advanced# advanced, extended, or basic
420421
#sql_inheritance = on
421422

‎src/bin/psql/common.c

Lines changed: 24 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.c,v 1.114 2006/03/05 15:58:51 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.115 2006/03/06 19:49:20 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -1328,6 +1328,29 @@ is_superuser(void)
13281328
}
13291329

13301330

1331+
/*
1332+
* Test if the current session uses standard string literals.
1333+
*
1334+
* Note: this will correctly detect the setting only with a protocol-3.0
1335+
* or newer backend; otherwise it will always say "false".
1336+
*/
1337+
bool
1338+
standard_strings(void)
1339+
{
1340+
constchar*val;
1341+
1342+
if (!pset.db)
1343+
return false;
1344+
1345+
val=PQparameterStatus(pset.db,"standard_conforming_strings");
1346+
1347+
if (val&&strcmp(val,"on")==0)
1348+
return true;
1349+
1350+
return false;
1351+
}
1352+
1353+
13311354
/*
13321355
* Return the session user of the current connection.
13331356
*

‎src/bin/psql/common.h

Lines changed: 2 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.46 2006/03/05 15:58:51 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.47 2006/03/06 19:49:20 momjian Exp $
77
*/
88
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -57,6 +57,7 @@ extern PGresult *PSQLexec(const char *query, bool start_xact);
5757
externboolSendQuery(constchar*query);
5858

5959
externboolis_superuser(void);
60+
externboolstandard_strings(void);
6061
externconstchar*session_username(void);
6162

6263
externchar*expand_tilde(char**filename);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp