mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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.
This commit is contained in:
@ -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]));
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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} {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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,SQL>{xqstart} {
|
||||
<C>{xqstart} {
|
||||
warn_on_first_escape = false;
|
||||
token_start = yytext;
|
||||
state_before = YYSTATE;
|
||||
BEGIN(xe);
|
||||
startlit();
|
||||
}
|
||||
<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);
|
||||
|
@ -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 | \\
|
||||
|
Reference in New Issue
Block a user