diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-05-11 19:15:36 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-05-11 19:15:36 +0000 |
commit | 637028afe17b9616d279d13d9fc5d6df1ecf369b (patch) | |
tree | 1e95735e0563109cd859edf95e268a5287a97aae | |
parent | 3fdeb189e977ebe29ee658592d07930e016dd031 (diff) | |
download | postgresql-637028afe17b9616d279d13d9fc5d6df1ecf369b.tar.gz postgresql-637028afe17b9616d279d13d9fc5d6df1ecf369b.zip |
Code review for standard_conforming_strings patch. Fix it so it does not
throw warnings for 100%-SQL-standard constructs, clean up some minor
infelicities, try to un-break ecpg to the best of my ability. (It's not clear
how ecpg is going to find out the setting of standard_conforming_strings,
though.) I think pg_dump still needs work, too.
-rw-r--r-- | doc/src/sgml/config.sgml | 59 | ||||
-rw-r--r-- | src/backend/parser/scan.l | 17 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 3 | ||||
-rw-r--r-- | src/backend/utils/misc/postgresql.conf.sample | 6 | ||||
-rw-r--r-- | src/bin/psql/common.c | 6 | ||||
-rw-r--r-- | src/bin/psql/psqlscan.l | 4 | ||||
-rw-r--r-- | src/include/parser/gramparse.h | 7 | ||||
-rw-r--r-- | src/include/utils/guc.h | 4 | ||||
-rw-r--r-- | src/interfaces/ecpg/preproc/pgc.l | 39 | ||||
-rw-r--r-- | src/test/regress/expected/strings.out | 24 |
10 files changed, 80 insertions, 89 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 933ca3811dc..a2e6d46ca6a 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.57 2006/05/02 18:07:51 tgl Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.58 2006/05/11 19:15:35 tgl Exp $ --> <chapter Id="runtime-config"> <title>Server Configuration</title> @@ -3734,32 +3734,15 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' <para> When on, a warning is issued if a backslash (<literal>\</>) appears in an ordinary string literal (<literal>'...'</> - syntax). The default is <literal>on</>. + syntax) and <varname>standard_conforming_strings</varname> is off. + The default is <literal>on</>. </para> <para> - Escape string syntax (<literal>E'...'</>) should be used for - backslash escape sequences, because ordinary strings have - the standard-conforming behavior of treating backslashes - literally when the <literal>standard-conforming-strings</> - option is set <literal>on</>. - </para> - </listitem> - </varlistentry> - - <varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings"> - <term><varname>standard_conforming_strings</varname> (<type>boolean</type>)</term> - <indexterm><primary>strings</><secondary>standard conforming</></> - <indexterm> - <primary><varname>standard_conforming_strings</> configuration parameter</primary> - </indexterm> - <listitem> - <para> - Controls whether ordinary string literals - (<literal>'...'</>) treat backslashes literally, as specified in - the SQL standard. Applications may check this - parameter to determine how string literals will be processed. - The presence of this parameter can also be taken as an indication - that the escape string syntax (<literal>E'...'</>) is supported. + Applications that wish to use backslash as escape should be + modified to use escape string syntax (<literal>E'...'</>), + because the default behavior of ordinary strings will change + in a future release for SQL compatibility. This variable can + be enabled to help detect applications that will break. </para> </listitem> </varlistentry> @@ -3799,6 +3782,32 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' </listitem> </varlistentry> + <varlistentry id="guc-standard-conforming-strings" xreflabel="standard_conforming_strings"> + <term><varname>standard_conforming_strings</varname> (<type>boolean</type>)</term> + <indexterm><primary>strings</><secondary>standard conforming</></> + <indexterm> + <primary><varname>standard_conforming_strings</> configuration parameter</primary> + </indexterm> + <listitem> + <para> + This controls whether ordinary string literals + (<literal>'...'</>) treat backslashes literally, as specified in + the SQL standard. + The default is currently <literal>off</>, causing + <productname>PostgreSQL</productname> to have its historical + behavior of treating backslashes as escape characters. + The default will change to <literal>on</> in a future release + to improve compatibility with the standard. + Applications may check this + parameter to determine how string literals will be processed. + The presence of this parameter can also be taken as an indication + that the escape string syntax (<literal>E'...'</>) is supported. + Escape string syntax should be used if an application desires + backslashes to be treated as escape characters. + </para> + </listitem> + </varlistentry> + </variablelist> </sect2> diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l index 0ac8d346a7b..78a888e02af 100644 --- a/src/backend/parser/scan.l +++ b/src/backend/parser/scan.l @@ -24,7 +24,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.133 2006/03/14 22:48:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.134 2006/05/11 19:15:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -51,12 +51,12 @@ static char *dolqstart; /* current $foo$ quote start string */ /* * GUC variables. This is a DIRECT violation of the warning given at the * head of gram.y, ie flex/bison code must not depend on any GUC variables; - * as such, changing its value can induce very unintuitive behavior. + * as such, changing their values can induce very unintuitive behavior. * But we shall have to live with it as a short-term thing until the switch * to SQL-standard string syntax is complete. */ -bool escape_string_warning; -bool standard_conforming_strings; +bool escape_string_warning = true; +bool standard_conforming_strings = false; static bool warn_on_first_escape; @@ -211,8 +211,7 @@ xehexesc [\\]x[0-9A-Fa-f]{1,2} */ xqstart {quote} xqdouble {quote}{quote} -xqinside [^\\']+ -xqbackslash [\\] +xqinside [^']+ /* $foo$ style quotes ("dollar quoting") * The quoted string starts with $foo$ where "foo" is an optional string @@ -443,7 +442,7 @@ other . yylval.str = litbufdup(); return SCONST; } -<xq,xe>{xqdouble} { +<xq,xe>{xqdouble} { addlitchar('\''); } <xq>{xqinside} { @@ -452,10 +451,6 @@ other . <xe>{xeinside} { addlit(yytext, yyleng); } -<xq>{xqbackslash} { - check_string_escape_warning(yytext[1]); - addlitchar('\\'); - } <xe>{xeescape} { check_string_escape_warning(yytext[1]); addlitchar(unescape_single_char(yytext[1])); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index c2c1318b4cb..87df3fdbacd 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut <peter_e@gmx.net>. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.318 2006/05/02 11:28:55 teodor Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.319 2006/05/11 19:15:35 tgl Exp $ * *-------------------------------------------------------------------- */ @@ -46,6 +46,7 @@ #include "optimizer/geqo.h" #include "optimizer/paths.h" #include "optimizer/planmain.h" +#include "parser/gramparse.h" #include "parser/parse_expr.h" #include "parser/parse_relation.h" #include "parser/scansup.h" diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 84c9f795848..dac59378a07 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -279,7 +279,7 @@ # warning # error # panic(off) - + #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements # and their durations, in milliseconds. @@ -415,8 +415,8 @@ #add_missing_from = off #array_nulls = on #default_with_oids = off -escape_string_warning = on # warn about backslashes in string literals -#standard_conforming_strings = off # SQL standard string literal processing +#escape_string_warning = on +#standard_conforming_strings = off #regex_flavor = advanced # advanced, extended, or basic #sql_inheritance = on diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index ec0acc156e7..ba8e403dd2a 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.116 2006/03/14 22:48:22 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.117 2006/05/11 19:15:35 tgl Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -1101,8 +1101,8 @@ is_superuser(void) /* * Test if the current session uses standard string literals. * - * Note: this will correctly detect the setting only with a protocol-3.0 - * or newer backend; otherwise it will always say "false". + * Note: With a pre-protocol-3.0 connection this will always say "false", + * which should be the right answer. */ bool standard_strings(void) diff --git a/src/bin/psql/psqlscan.l b/src/bin/psql/psqlscan.l index 6c04aaf30ba..4a344baf6b2 100644 --- a/src/bin/psql/psqlscan.l +++ b/src/bin/psql/psqlscan.l @@ -33,7 +33,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.17 2006/03/06 19:49:20 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.18 2006/05/11 19:15:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -467,7 +467,7 @@ other . BEGIN(INITIAL); ECHO; } -<xq,xe>{xqdouble} { +<xq,xe>{xqdouble} { ECHO; } <xq>{xqinside} { diff --git a/src/include/parser/gramparse.h b/src/include/parser/gramparse.h index 13af69116cd..8430ad8c8e8 100644 --- a/src/include/parser/gramparse.h +++ b/src/include/parser/gramparse.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/gramparse.h,v 1.34 2006/03/14 22:48:22 tgl Exp $ + * $PostgreSQL: pgsql/src/include/parser/gramparse.h,v 1.35 2006/05/11 19:15:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,6 +27,11 @@ */ #define YYLTYPE int +/* GUC variables in scan.l (every one of these is a bad idea :-() */ +extern bool escape_string_warning; +extern bool standard_conforming_strings; + + /* from scan.l */ extern void scanner_init(const char *str); extern void scanner_finish(void); diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index d60f5061b26..182a762cc02 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -7,7 +7,7 @@ * Copyright (c) 2000-2006, PostgreSQL Global Development Group * Written by Peter Eisentraut <peter_e@gmx.net>. * - * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.67 2006/03/07 03:01:22 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.68 2006/05/11 19:15:35 tgl Exp $ *-------------------------------------------------------------------- */ #ifndef GUC_H @@ -120,8 +120,6 @@ extern bool SQL_inheritance; extern bool Australian_timezones; extern bool default_with_oids; -extern bool escape_string_warning; -extern bool standard_conforming_strings; extern int log_min_error_statement; extern int log_min_messages; diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 67f2517d21f..a835a1da696 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.145 2006/03/06 19:49:20 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.146 2006/05/11 19:15:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,8 +29,8 @@ extern YYSTYPE yylval; static int xcdepth = 0; /* depth of nesting in slash-star comments */ static char *dolqstart; /* current $foo$ quote start string */ -bool escape_string_warning; -bool standard_conforming_strings; +static bool escape_string_warning; +static bool standard_conforming_strings; static bool warn_on_first_escape; /* @@ -128,10 +128,10 @@ xnstart [nN]{quote} /* Quoted string that allows backslash escapes */ xestart [eE]{quote} -xeinside [^\\']+ -xeescape [\\][^0-7] -xeoctesc [\\][0-7]{1,3} -xehexesc [\\]x[0-9A-Fa-f]{1,2} +xeinside [^\\']+ +xeescape [\\][^0-7] +xeoctesc [\\][0-7]{1,3} +xehexesc [\\]x[0-9A-Fa-f]{1,2} /* C version of hex number */ xch 0[xX][0-9A-Fa-f]* @@ -141,8 +141,7 @@ xch 0[xX][0-9A-Fa-f]* */ xqstart {quote} xqdouble {quote}{quote} -xqinside [^\\']+ -xqbackslash [\\] +xqinside [^']+ /* $foo$ style quotes ("dollar quoting") * The quoted string starts with $foo$ where "foo" is an optional string @@ -402,11 +401,23 @@ cppline {space}*#(.*\\{space})*.*{newline} /* National character. * Transfer it as-is to the backend. */ + warn_on_first_escape = true; token_start = yytext; - BEGIN(xq); + state_before = YYSTATE; + if (standard_conforming_strings) + BEGIN(xq); + else + BEGIN(xe); + startlit(); + } +<C>{xqstart} { + warn_on_first_escape = false; + token_start = yytext; + state_before = YYSTATE; + BEGIN(xe); startlit(); } -<C,SQL>{xqstart} { +<SQL>{xqstart} { warn_on_first_escape = true; token_start = yytext; state_before = YYSTATE; @@ -416,7 +427,7 @@ cppline {space}*#(.*\\{space})*.*{newline} BEGIN(xe); startlit(); } -<C,SQL>{xestart} { +<SQL>{xestart} { warn_on_first_escape = false; token_start = yytext; state_before = YYSTATE; @@ -433,10 +444,6 @@ cppline {space}*#(.*\\{space})*.*{newline} <xq,xe>{xqdouble} { addlitchar('\''); } <xq>{xqinside} { addlit(yytext, yyleng); } <xe>{xeinside} { addlit(yytext, yyleng); } -<xq>{xqbackslash} { - check_escape_warning(); - addlitchar('\\'); - } <xe>{xeescape} { check_escape_warning(); addlit(yytext, yyleng); diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out index 0c9b88ee8f0..20081f699b6 100644 --- a/src/test/regress/expected/strings.out +++ b/src/test/regress/expected/strings.out @@ -927,30 +927,6 @@ show standard_conforming_strings; (1 row) select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6; -WARNING: nonstandard use of escape in a string literal -LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a... - ^ -HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. -WARNING: nonstandard use of escape in a string literal -LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a... - ^ -HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. -WARNING: nonstandard use of escape in a string literal -LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a... - ^ -HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. -WARNING: nonstandard use of escape in a string literal -LINE 1: ...a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' ... - ^ -HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. -WARNING: nonstandard use of escape in a string literal -LINE 1: ...b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' ... - ^ -HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. -WARNING: nonstandard use of escape in a string literal -LINE 1: ...b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6... - ^ -HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. f1 | f2 | f3 | f4 | f5 | f6 -------+--------+---------+-------+--------+---- a\bcd | a\b'cd | a\b''cd | abcd\ | ab\'cd | \\ |