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

Commit637028a

Browse files
committed
Code review for standard_conforming_strings patch. Fix it so it does not
throw warnings for 100%-SQL-standard constructs, clean up some minorinfelicities, try to un-break ecpg to the best of my ability. (It's not clearhow ecpg is going to find out the setting of standard_conforming_strings,though.) I think pg_dump still needs work, too.
1 parent3fdeb18 commit637028a

File tree

10 files changed

+80
-89
lines changed

10 files changed

+80
-89
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.57 2006/05/02 18:07:51 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.58 2006/05/11 19:15:35 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -3734,32 +3734,15 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
37343734
<para>
37353735
When on, a warning is issued if a backslash (<literal>\</>)
37363736
appears in an ordinary string literal (<literal>'...'</>
3737-
syntax). The default is <literal>on</>.
3737+
syntax) and <varname>standard_conforming_strings</varname> is off.
3738+
The default is <literal>on</>.
37383739
</para>
37393740
<para>
3740-
Escape string syntax (<literal>E'...'</>) should be used for
3741-
backslash escape sequences, because ordinary strings have
3742-
the standard-conforming behavior of treating backslashes
3743-
literally when the <literal>standard-conforming-strings</>
3744-
option is set <literal>on</>.
3745-
</para>
3746-
</listitem>
3747-
</varlistentry>
3748-
3749-
<varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings">
3750-
<term><varname>standard_conforming_strings</varname> (<type>boolean</type>)</term>
3751-
<indexterm><primary>strings</><secondary>standard conforming</></>
3752-
<indexterm>
3753-
<primary><varname>standard_conforming_strings</> configuration parameter</primary>
3754-
</indexterm>
3755-
<listitem>
3756-
<para>
3757-
Controls whether ordinary string literals
3758-
(<literal>'...'</>) treat backslashes literally, as specified in
3759-
the SQL standard. Applications may check this
3760-
parameter to determine how string literals will be processed.
3761-
The presence of this parameter can also be taken as an indication
3762-
that the escape string syntax (<literal>E'...'</>) is supported.
3741+
Applications that wish to use backslash as escape should be
3742+
modified to use escape string syntax (<literal>E'...'</>),
3743+
because the default behavior of ordinary strings will change
3744+
in a future release for SQL compatibility. This variable can
3745+
be enabled to help detect applications that will break.
37633746
</para>
37643747
</listitem>
37653748
</varlistentry>
@@ -3799,6 +3782,32 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
37993782
</listitem>
38003783
</varlistentry>
38013784

3785+
<varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings">
3786+
<term><varname>standard_conforming_strings</varname> (<type>boolean</type>)</term>
3787+
<indexterm><primary>strings</><secondary>standard conforming</></>
3788+
<indexterm>
3789+
<primary><varname>standard_conforming_strings</> configuration parameter</primary>
3790+
</indexterm>
3791+
<listitem>
3792+
<para>
3793+
This controls whether ordinary string literals
3794+
(<literal>'...'</>) treat backslashes literally, as specified in
3795+
the SQL standard.
3796+
The default is currently <literal>off</>, causing
3797+
<productname>PostgreSQL</productname> to have its historical
3798+
behavior of treating backslashes as escape characters.
3799+
The default will change to <literal>on</> in a future release
3800+
to improve compatibility with the standard.
3801+
Applications may check this
3802+
parameter to determine how string literals will be processed.
3803+
The presence of this parameter can also be taken as an indication
3804+
that the escape string syntax (<literal>E'...'</>) is supported.
3805+
Escape string syntax should be used if an application desires
3806+
backslashes to be treated as escape characters.
3807+
</para>
3808+
</listitem>
3809+
</varlistentry>
3810+
38023811
</variablelist>
38033812
</sect2>
38043813

‎src/backend/parser/scan.l

Lines changed: 6 additions & 11 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.133 2006/03/14 22:48:21 tgl Exp $
27+
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.134 2006/05/11 19:15:35 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -51,12 +51,12 @@ static char *dolqstart; /* current $foo$ quote start string */
5151
/*
5252
* GUC variables. This is a DIRECT violation of the warning given at the
5353
* head of gram.y, ie flex/bison code must not depend on any GUC variables;
54-
* as such, changingits value can induce very unintuitive behavior.
54+
* as such, changingtheir values can induce very unintuitive behavior.
5555
* But we shall have to live with it as a short-term thing until the switch
5656
* to SQL-standard string syntax is complete.
5757
*/
58-
boolescape_string_warning;
59-
boolstandard_conforming_strings;
58+
boolescape_string_warning =true;
59+
boolstandard_conforming_strings =false;
6060

6161
staticboolwarn_on_first_escape;
6262

@@ -211,8 +211,7 @@ xehexesc[\\]x[0-9A-Fa-f]{1,2}
211211
*/
212212
xqstart{quote}
213213
xqdouble{quote}{quote}
214-
xqinside[^\\']+
215-
xqbackslash[\\]
214+
xqinside[^']+
216215

217216
/* $foo$ style quotes ("dollar quoting")
218217
* The quoted string starts with $foo$ where "foo" is an optional string
@@ -443,7 +442,7 @@ other.
443442
yylval.str =litbufdup();
444443
return SCONST;
445444
}
446-
<xq,xe>{xqdouble}{
445+
<xq,xe>{xqdouble} {
447446
addlitchar('\'');
448447
}
449448
<xq>{xqinside} {
@@ -452,10 +451,6 @@ other.
452451
<xe>{xeinside} {
453452
addlit(yytext, yyleng);
454453
}
455-
<xq>{xqbackslash} {
456-
check_string_escape_warning(yytext[1]);
457-
addlitchar('\\');
458-
}
459454
<xe>{xeescape} {
460455
check_string_escape_warning(yytext[1]);
461456
addlitchar(unescape_single_char(yytext[1]));

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

Lines changed: 2 additions & 1 deletion
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.318 2006/05/02 11:28:55 teodor Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.319 2006/05/11 19:15:35 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -46,6 +46,7 @@
4646
#include"optimizer/geqo.h"
4747
#include"optimizer/paths.h"
4848
#include"optimizer/planmain.h"
49+
#include"parser/gramparse.h"
4950
#include"parser/parse_expr.h"
5051
#include"parser/parse_relation.h"
5152
#include"parser/scansup.h"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279
# warning
280280
# error
281281
# panic(off)
282-
282+
283283
#log_min_duration_statement = -1# -1 is disabled, 0 logs all statements
284284
# and their durations, in milliseconds.
285285

@@ -415,8 +415,8 @@
415415
#add_missing_from = off
416416
#array_nulls = on
417417
#default_with_oids = off
418-
escape_string_warning = on# warn about backslashes in string literals
419-
#standard_conforming_strings = off# SQL standard string literal processing
418+
#escape_string_warning = on
419+
#standard_conforming_strings = off
420420
#regex_flavor = advanced# advanced, extended, or basic
421421
#sql_inheritance = on
422422

‎src/bin/psql/common.c

Lines changed: 3 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/common.c,v 1.116 2006/03/14 22:48:22 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.117 2006/05/11 19:15:35 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -1101,8 +1101,8 @@ is_superuser(void)
11011101
/*
11021102
* Test if the current session uses standard string literals.
11031103
*
1104-
* Note:this will correctly detect the setting only with aprotocol-3.0
1105-
*or newer backend; otherwise it will always say "false".
1104+
* Note:With a pre-protocol-3.0 connection this will always say "false",
1105+
*which should be the right answer.
11061106
*/
11071107
bool
11081108
standard_strings(void)

‎src/bin/psql/psqlscan.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* Portions Copyright (c) 1994, Regents of the University of California
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.17 2006/03/06 19:49:20 momjian Exp $
36+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.18 2006/05/11 19:15:35 tgl Exp $
3737
*
3838
*-------------------------------------------------------------------------
3939
*/
@@ -467,7 +467,7 @@ other.
467467
BEGIN(INITIAL);
468468
ECHO;
469469
}
470-
<xq,xe>{xqdouble}{
470+
<xq,xe>{xqdouble} {
471471
ECHO;
472472
}
473473
<xq>{xqinside} {

‎src/include/parser/gramparse.h

Lines changed: 6 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/include/parser/gramparse.h,v 1.34 2006/03/14 22:48:22 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/parser/gramparse.h,v 1.35 2006/05/11 19:15:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,6 +27,11 @@
2727
*/
2828
#defineYYLTYPE int
2929

30+
/* GUC variables in scan.l (every one of these is a bad idea :-() */
31+
externboolescape_string_warning;
32+
externboolstandard_conforming_strings;
33+
34+
3035
/* from scan.l */
3136
externvoidscanner_init(constchar*str);
3237
externvoidscanner_finish(void);

‎src/include/utils/guc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.67 2006/03/07 03:01:22 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.68 2006/05/11 19:15:35 tgl Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndefGUC_H
@@ -120,8 +120,6 @@ extern bool SQL_inheritance;
120120
externboolAustralian_timezones;
121121

122122
externbooldefault_with_oids;
123-
externboolescape_string_warning;
124-
externboolstandard_conforming_strings;
125123

126124
externintlog_min_error_statement;
127125
externintlog_min_messages;

‎src/interfaces/ecpg/preproc/pgc.l

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.145 2006/03/06 19:49:20 momjian Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.146 2006/05/11 19:15:36 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -29,8 +29,8 @@ extern YYSTYPE yylval;
2929

3030
staticintxcdepth =0;/* depth of nesting in slash-star comments*/
3131
staticchar *dolqstart;/* current $foo$ quote start string*/
32-
boolescape_string_warning;
33-
boolstandard_conforming_strings;
32+
staticboolescape_string_warning;
33+
staticboolstandard_conforming_strings;
3434
staticbool warn_on_first_escape;
3535

3636
/*
@@ -128,10 +128,10 @@ xnstart[nN]{quote}
128128

129129
/* Quoted string that allows backslash escapes */
130130
xestart [eE]{quote}
131-
xeinside[^\\']+
132-
xeescape[\\][^0-7]
133-
xeoctesc[\\][0-7]{1,3}
134-
xehexesc[\\]x[0-9A-Fa-f]{1,2}
131+
xeinside[^\\']+
132+
xeescape[\\][^0-7]
133+
xeoctesc[\\][0-7]{1,3}
134+
xehexesc[\\]x[0-9A-Fa-f]{1,2}
135135

136136
/* C version of hex number */
137137
xch0[xX][0-9A-Fa-f]*
@@ -141,8 +141,7 @@ xch0[xX][0-9A-Fa-f]*
141141
*/
142142
xqstart{quote}
143143
xqdouble{quote}{quote}
144-
xqinside[^\\']+
145-
xqbackslash[\\]
144+
xqinside[^']+
146145

147146
/* $foo$ style quotes ("dollar quoting")
148147
* The quoted string starts with $foo$ where "foo" is an optional string
@@ -402,11 +401,23 @@ cppline{space}*#(.*\\{space})*.*{newline}
402401
/* National character.
403402
* Transfer it as-is to the backend.
404403
*/
404+
warn_on_first_escape =true;
405405
token_start = yytext;
406-
BEGIN(xq);
406+
state_before = YYSTATE;
407+
if (standard_conforming_strings)
408+
BEGIN(xq);
409+
else
410+
BEGIN(xe);
411+
startlit();
412+
}
413+
<C>{xqstart}{
414+
warn_on_first_escape =false;
415+
token_start = yytext;
416+
state_before = YYSTATE;
417+
BEGIN(xe);
407418
startlit();
408419
}
409-
<C,SQL>{xqstart}{
420+
<SQL>{xqstart}{
410421
warn_on_first_escape =true;
411422
token_start = yytext;
412423
state_before = YYSTATE;
@@ -416,7 +427,7 @@ cppline{space}*#(.*\\{space})*.*{newline}
416427
BEGIN(xe);
417428
startlit();
418429
}
419-
<C,SQL>{xestart}{
430+
<SQL>{xestart}{
420431
warn_on_first_escape =false;
421432
token_start = yytext;
422433
state_before = YYSTATE;
@@ -433,10 +444,6 @@ cppline{space}*#(.*\\{space})*.*{newline}
433444
<xq,xe>{xqdouble}{addlitchar('\''); }
434445
<xq>{xqinside}{addlit(yytext, yyleng); }
435446
<xe>{xeinside}{addlit(yytext, yyleng); }
436-
<xq>{xqbackslash} {
437-
check_escape_warning();
438-
addlitchar('\\');
439-
}
440447
<xe>{xeescape} {
441448
check_escape_warning();
442449
addlit(yytext, yyleng);

‎src/test/regress/expected/strings.out

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -927,30 +927,6 @@ show standard_conforming_strings;
927927
(1 row)
928928

929929
select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
930-
WARNING: nonstandard use of escape in a string literal
931-
LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a...
932-
^
933-
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
934-
WARNING: nonstandard use of escape in a string literal
935-
LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a...
936-
^
937-
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
938-
WARNING: nonstandard use of escape in a string literal
939-
LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a...
940-
^
941-
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
942-
WARNING: nonstandard use of escape in a string literal
943-
LINE 1: ...a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' ...
944-
^
945-
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
946-
WARNING: nonstandard use of escape in a string literal
947-
LINE 1: ...b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' ...
948-
^
949-
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
950-
WARNING: nonstandard use of escape in a string literal
951-
LINE 1: ...b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6...
952-
^
953-
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
954930
f1 | f2 | f3 | f4 | f5 | f6
955931
-------+--------+---------+-------+--------+----
956932
a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp