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

Commitd395aec

Browse files
committed
Code review for escape-strings patch. Sync psql and plpgsql lexers
with main, avoid using a SQL-defined SQLSTATE for what is most definitelynot a SQL-compatible error condition, fix documentation omissions,adhere to message style guidelines, don't use two GUC_REPORT variableswhen one is sufficient. Nothing done about pg_dump issues.
1 parent3cbd6bc commitd395aec

File tree

10 files changed

+134
-82
lines changed

10 files changed

+134
-82
lines changed

‎doc/src/sgml/errcodes.sgml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.12 2005/01/06 01:49:24 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.13 2005/06/26 19:16:04 tgl Exp $ -->
22

33
<appendix id="errcodes-appendix">
44
<title><productname>PostgreSQL</productname> Error Codes</title>
@@ -370,6 +370,11 @@
370370
<entry>INVALID ESCAPE SEQUENCE</entry>
371371
</row>
372372

373+
<row>
374+
<entry><literal>22P06</literal></entry>
375+
<entry>NONSTANDARD USE OF ESCAPE CHARACTER</entry>
376+
</row>
377+
373378
<row>
374379
<entry><literal>22010</literal></entry>
375380
<entry>INVALID INDICATOR PARAMETER VALUE</entry>

‎doc/src/sgml/libpq.sgml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.186 2005/06/21 04:02:29 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.187 2005/06/26 19:16:04 tgl Exp $
33
-->
44

55
<chapter id="libpq">
@@ -286,7 +286,7 @@ PGconn *PQconnectdb(const char *conninfo);
286286
Kerberos service name to use when authenticating with Kerberos 4 or 5.
287287
This must match the service name specified in the server
288288
configuration for Kerberos authentication to succeed. (See also
289-
<xref linkend="kerberos-auth">.)
289+
<xref linkend="kerberos-auth">.)
290290
</para>
291291
</listitem>
292292
</varlistentry>
@@ -888,10 +888,13 @@ Parameters reported as of the current release include
888888
<literal>is_superuser</>,
889889
<literal>session_authorization</>,
890890
<literal>DateStyle</>,
891-
<literal>TimeZone</>, and
892-
<literal>integer_datetimes</>.
891+
<literal>TimeZone</>,
892+
<literal>integer_datetimes</>, and
893+
<literal>standard_compliant_strings</>.
893894
(<literal>server_encoding</>, <literal>TimeZone</>, and
894-
<literal>integer_datetimes</> were not reported by releases before 8.0.)
895+
<literal>integer_datetimes</> were not reported by releases before 8.0;
896+
<literal>standard_compliant_strings</> was not reported by releases
897+
before 8.1.)
895898
Note that
896899
<literal>server_version</>,
897900
<literal>server_encoding</> and
@@ -913,6 +916,14 @@ see also <function>PQserverVersion</>, which returns the information
913916
in a numeric form that is much easier to compare against.
914917
</para>
915918

919+
<para>
920+
If no value for <literal>standard_compliant_strings</> is reported,
921+
applications may assume it is <literal>false</>, that is, backslashes
922+
are treated as escapes in string literals. Also, the presence of this
923+
parameter may be taken as an indication that the escape string syntax
924+
(<literal>E'...'</>) is accepted.
925+
</para>
926+
916927
<para>
917928
Although the returned pointer is declared <literal>const</>, it in fact
918929
points to mutable storage associated with the <literal>PGconn</> structure.

‎doc/src/sgml/protocol.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/protocol.sgml,v 1.59 2005/06/22 15:19:43 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/protocol.sgml,v 1.60 2005/06/2619:16:04 tgl Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
@@ -1072,10 +1072,13 @@
10721072
<literal>is_superuser</>,
10731073
<literal>session_authorization</>,
10741074
<literal>DateStyle</>,
1075-
<literal>TimeZone</>, and
1076-
<literal>integer_datetimes</>.
1075+
<literal>TimeZone</>,
1076+
<literal>integer_datetimes</>, and
1077+
<literal>standard_compliant_strings</>.
10771078
(<literal>server_encoding</>, <literal>TimeZone</>, and
1078-
<literal>integer_datetimes</> were not reported by releases before 8.0.)
1079+
<literal>integer_datetimes</> were not reported by releases before 8.0;
1080+
<literal>standard_compliant_strings</> was not reported by releases
1081+
before 8.1.)
10791082
Note that
10801083
<literal>server_version</>,
10811084
<literal>server_encoding</> and

‎doc/src/sgml/runtime.sgml

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.331 2005/06/2603:03:17 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.332 2005/06/2619:16:04 tgl Exp $
33
-->
44

55
<chapter Id="runtime">
@@ -3766,13 +3766,11 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
37663766
<listitem>
37673767
<para>
37683768
When <literal>on</>, a warning is issued if a backslash
3769-
(<literal>\</>) appears in a ordinary, non-escape syntax
3770-
(<literal>''</>) string. To log the statement that generated the
3771-
warning, set <varname>log_min_error_statement</> to
3772-
<literal>error</>. The default is off.
3769+
(<literal>\</>) appears in an ordinary string literal
3770+
(<literal>'...'</> syntax). The default is <literal>off</>.
37733771
</para>
37743772
<para>
3775-
Escape string syntax (<literal>E''</>) should be used for
3773+
Escape string syntax (<literal>E'...'</>) should be used for
37763774
escapes, because in future versions of
37773775
<productname>PostgreSQL</productname> ordinary strings will have
37783776
the standard-compliant behavior of treating backslashes
@@ -3988,33 +3986,24 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
39883986
</listitem>
39893987
</varlistentry>
39903988

3991-
<varlistentry id="guc-escape-string-syntax" xreflabel="escape_string_syntax">
3992-
<term><varname>escape_string_syntax</varname> (<type>boolean</type>)</term>
3993-
<indexterm><primary>strings</><secondary>escape</></>
3994-
<indexterm>
3995-
<primary><varname>escape_string_syntax</> configuration parameter</primary>
3996-
</indexterm>
3997-
<listitem>
3998-
<para>
3999-
Reports whether escape string syntax (<literal>E''</>) is
4000-
supported. This variable is used by applications that need to
4001-
determine if escape string syntax can be used in their code.
4002-
</para>
4003-
</listitem>
4004-
</varlistentry>
4005-
4006-
<varlistentry id="guc-sql-standard-strings" xreflabel="standard_compliant_strings">
3989+
<varlistentry id="guc-standard-compliant-strings" xreflabel="standard_compliant_strings">
40073990
<term><varname>standard_compliant_strings</varname> (<type>boolean</type>)</term>
40083991
<indexterm><primary>strings</><secondary>escape</></>
40093992
<indexterm>
40103993
<primary><varname>standard_compliant_strings</> configuration parameter</primary>
40113994
</indexterm>
40123995
<listitem>
40133996
<para>
4014-
Reports whether ordinary, non-escape syntax strings
4015-
(<literal>''</>) treat backslashes literally, as specified in
4016-
the SQL standard. This variable is used by applications that
4017-
need to know how ordinary strings are processed`.
3997+
Reports whether ordinary string literals
3998+
(<literal>'...'</>) treat backslashes literally, as specified in
3999+
the SQL standard. The value is currently always <literal>false</>,
4000+
indicating that backslashes are treated as escapes. It is planned
4001+
that this will change to <literal>true</> in a future
4002+
<productname>PostgreSQL</productname> release when string literal
4003+
syntax changes to meet the standard. Applications may check this
4004+
parameter to determine how string literals will be processed.
4005+
The presence of this parameter can also be taken as an indication
4006+
that the escape string syntax (<literal>E'...'</>) is supported.
40184007
</para>
40194008
</listitem>
40204009
</varlistentry>

‎doc/src/sgml/syntax.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.101 2005/06/2603:03:21 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.102 2005/06/2619:16:05 tgl Exp $
33
-->
44

55
<chapter id="sql-syntax">
@@ -249,7 +249,7 @@ UPDATE "my_table" SET "a" = 5;
249249
<productname>PostgreSQL</productname> also allows single quotes
250250
to be escaped with a backslash (<literal>\'</literal>). However,
251251
future versions of <productname>PostgreSQL</productname> will not
252-
support this so applications usingthis should convert to the
252+
allow this, so applications usingbackslashes should convert to the
253253
standard-compliant method outlined above.
254254
</para>
255255

@@ -276,8 +276,8 @@ UPDATE "my_table" SET "a" = 5;
276276
eventually treat backslashes as literal characters to be
277277
standard-compliant. The proper way to specify escape processing is
278278
to use the escape string syntax to indicate that escape
279-
processing is desired. Escape string syntax is specified byplacing
280-
thetheletter <literal>E</literal> (upper or lower case) before
279+
processing is desired. Escape string syntax is specified bywriting
280+
the letter <literal>E</literal> (upper or lower case) just before
281281
the string, e.g. <literal>E'\041'</>. This method will work in all
282282
future versions of <productname>PostgreSQL</productname>.
283283
</para>

‎src/backend/parser/scan.l

Lines changed: 38 additions & 18 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.126 2005/06/2603:03:38 momjian Exp $
27+
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.127 2005/06/2619:16:05 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -48,10 +48,19 @@
4848
extern YYSTYPE yylval;
4949

5050
staticintxcdepth =0;/* depth of nesting in slash-star comments*/
51-
staticchar *dolqstart;/* current $foo$ quote start string*/
52-
staticboolwarn_on_first_escape;
51+
staticchar *dolqstart;/* current $foo$ quote start string*/
52+
53+
/*
54+
* GUC variable. This is a DIRECT violation of the warning given at the
55+
* head of gram.y, ie flex/bison code must not depend on any GUC variables;
56+
* as such, changing its value can induce very unintuitive behavior.
57+
* But we shall have to live with it as a short-term thing until the switch
58+
* to SQL-standard string syntax is complete.
59+
*/
5360
boolescape_string_warning;
5461

62+
staticboolwarn_on_first_escape;
63+
5564
/*
5665
* literalbuf is used to accumulate literal values when multiple rules
5766
* are needed to parse a single literal. Call startlit to reset buffer
@@ -66,6 +75,7 @@ static intliteralalloc;/* current allocated buffer size */
6675
staticvoidaddlit(char *ytext,int yleng);
6776
staticvoidaddlitchar(unsignedchar ychar);
6877
staticchar *litbufdup(void);
78+
staticintpg_err_position(void);
6979
staticvoidcheck_escape_warning(void);
7080

7181
/*
@@ -188,9 +198,8 @@ xhinside[^']*
188198
/* National character */
189199
xnstart[nN]{quote}
190200

191-
/*Quote stringdoes not warn about escapes */
201+
/*Quoted stringthat allows backslash escapes */
192202
xestart[eE]{quote}
193-
xeinside[^']*
194203

195204
/* Extended quote
196205
* xqdouble implements embedded quote, ''''
@@ -446,17 +455,21 @@ other.
446455
{
447456
if (warn_on_first_escape && escape_string_warning)
448457
ereport(WARNING,
449-
(errcode(ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER),
450-
errmsg("Invalid use of\\' in a normal string"),
451-
errhint("Use '' to place quotes in strings, or use the escape string syntax (E'').")));
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 */
452463
}
453464
elseif (yytext[1] =='\\')
454465
{
455466
if (warn_on_first_escape && escape_string_warning)
456467
ereport(WARNING,
457-
(errcode(ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER),
458-
errmsg("Invalid use of\\\\ in a normal string"),
459-
errhint("Use the escape string syntax for backslashes, e.g. E'\\\\'.")));
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 */
460473
}
461474
else
462475
check_escape_warning();
@@ -707,14 +720,20 @@ other.
707720

708721
%%
709722

710-
void
711-
yyerror(constchar *message)
723+
staticint
724+
pg_err_position(void)
712725
{
713726
constchar *loc = token_start ? token_start : yytext;
714-
intcursorpos;
715727

716728
/* in multibyte encodings, return index in characters not bytes */
717-
cursorpos =pg_mbstrlen_with_len(scanbuf, loc - scanbuf) +1;
729+
returnpg_mbstrlen_with_len(scanbuf, loc - scanbuf) +1;
730+
}
731+
732+
void
733+
yyerror(constchar *message)
734+
{
735+
constchar *loc = token_start ? token_start : yytext;
736+
intcursorpos =pg_err_position();
718737

719738
if (*loc == YY_END_OF_BUFFER_CHAR)
720739
{
@@ -852,8 +871,9 @@ check_escape_warning(void)
852871
{
853872
if (warn_on_first_escape && escape_string_warning)
854873
ereport(WARNING,
855-
(errcode(ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER),
856-
errmsg("Invalid use of escapes in an ordinary string"),
857-
errhint("Use the escape string syntax for escapes, e.g. E'\\r\\n'.")));
874+
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
875+
errmsg("nonstandard use of escape in a string literal"),
876+
errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."),
877+
errposition(pg_err_position())));
858878
warn_on_first_escape =false;/* warn only once per string */
859879
}

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

Lines changed: 3 additions & 14 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.269 2005/06/2603:03:41 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.270 2005/06/2619:16:06 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -190,7 +190,6 @@ static intmax_index_keys;
190190
staticintmax_identifier_length;
191191
staticintblock_size;
192192
staticboolinteger_datetimes;
193-
staticboolescape_string_syntax;
194193
staticboolstandard_compliant_strings;
195194

196195
/* should be static, but commands/variable.c needs to get at it */
@@ -877,26 +876,16 @@ static struct config_bool ConfigureNamesBool[] =
877876

878877
{
879878
{"escape_string_warning",PGC_USERSET,COMPAT_OPTIONS_PREVIOUS,
880-
gettext_noop("Warn about backslash escapes in ordinary, non-escape-syntax strings."),
879+
gettext_noop("Warn about backslash escapes in ordinary string literals."),
881880
NULL
882881
},
883882
&escape_string_warning,
884883
false,NULL,NULL
885884
},
886885

887-
{
888-
{"escape_string_syntax",PGC_INTERNAL,PRESET_OPTIONS,
889-
gettext_noop("Escape string syntax (E'') is supported."),
890-
NULL,
891-
GUC_REPORT |GUC_NOT_IN_SAMPLE |GUC_DISALLOW_IN_FILE
892-
},
893-
&escape_string_syntax,
894-
true,NULL,NULL
895-
},
896-
897886
{
898887
{"standard_compliant_strings",PGC_INTERNAL,PRESET_OPTIONS,
899-
gettext_noop("'' strings treat backslashes literally."),
888+
gettext_noop("'...' strings treat backslashes literally."),
900889
NULL,
901890
GUC_REPORT |GUC_NOT_IN_SAMPLE |GUC_DISALLOW_IN_FILE
902891
},

‎src/bin/psql/psqlscan.l

Lines changed: 11 additions & 6 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.14 2005/06/02 17:45:19 tgl Exp $
36+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.15 2005/06/26 19:16:06 tgl Exp $
3737
*
3838
*-------------------------------------------------------------------------
3939
*/
@@ -235,17 +235,18 @@ quotefail{quote}{whitespace}*"-"
235235
xbstart[bB]{quote}
236236
xbinside[^']*
237237
238-
/* Hexadecimal number
239-
*/
238+
/* Hexadecimal number */
240239
xhstart[xX]{quote}
241240
xhinside[^']*
242241

243-
/* National character
244-
*/
242+
/* National character*/
245243
xnstart[nN]{quote}
246244

245+
/* Quoted string that allows backslash escapes*/
246+
xestart[eE]{quote}
247+
247248
/* Extended quote
248-
* xqdouble implements embedded quote
249+
* xqdouble implements embedded quote, ''''
249250
*/
250251
xqstart{quote}
251252
xqdouble{quote}{quote}
@@ -450,6 +451,10 @@ other.
450451
BEGIN(xq);
451452
ECHO;
452453
}
454+
{xestart}{
455+
BEGIN(xq);
456+
ECHO;
457+
}
453458
<xq>{quotestop}|
454459
<xq>{quotefail} {
455460
yyless(1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp