diff options
author | Bruce Momjian <bruce@momjian.us> | 2006-03-06 19:49:20 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2006-03-06 19:49:20 +0000 |
commit | 19c21d115d221d9738afad142f2886dfd3cc40de (patch) | |
tree | f5a4a3f11ae8a6efe639a8717f5fa2c267dbd7b0 /src/bin/psql | |
parent | a9c1047ebdde533949fd8096c8ac1eca5e821292 (diff) | |
download | postgresql-19c21d115d221d9738afad142f2886dfd3cc40de.tar.gz postgresql-19c21d115d221d9738afad142f2886dfd3cc40de.zip |
Enable standard_conforming_strings to be turned on.
Kevin Grittner
Diffstat (limited to 'src/bin/psql')
-rw-r--r-- | src/bin/psql/common.c | 25 | ||||
-rw-r--r-- | src/bin/psql/common.h | 3 | ||||
-rw-r--r-- | src/bin/psql/psqlscan.l | 49 |
3 files changed, 57 insertions, 20 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index ee1333e1ddc..07f4d22c070 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.114 2006/03/05 15:58:51 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.115 2006/03/06 19:49:20 momjian Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -1329,6 +1329,29 @@ 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". + */ +bool +standard_strings(void) +{ + const char *val; + + if (!pset.db) + return false; + + val = PQparameterStatus(pset.db, "standard_conforming_strings"); + + if (val && strcmp(val, "on") == 0) + return true; + + return false; +} + + +/* * Return the session user of the current connection. * * Note: this will correctly detect the session user only with a diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 70bb10d6700..b12ccdec575 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.46 2006/03/05 15:58:51 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.47 2006/03/06 19:49:20 momjian Exp $ */ #ifndef COMMON_H #define COMMON_H @@ -57,6 +57,7 @@ extern PGresult *PSQLexec(const char *query, bool start_xact); extern bool SendQuery(const char *query); extern bool is_superuser(void); +extern bool standard_strings(void); extern const char *session_username(void); extern char *expand_tilde(char **filename); diff --git a/src/bin/psql/psqlscan.l b/src/bin/psql/psqlscan.l index 2341527ccbf..6c04aaf30ba 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.16 2006/03/05 15:58:52 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.17 2006/03/06 19:49:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -154,7 +154,8 @@ static void emit(const char *txt, int len); * <xc> extended C-style comments * <xd> delimited identifiers (double-quoted identifiers) * <xh> hexadecimal numeric string - * <xq> quoted strings + * <xq> standard quoted strings + * <xe> extended quoted strings (support backslash escape sequences) * <xdolq> $foo$ quoted strings */ @@ -162,6 +163,7 @@ static void emit(const char *txt, int len); %x xc %x xd %x xh +%x xe %x xq %x xdolq /* Additional exclusive states for psql only: lex backslash commands */ @@ -244,16 +246,17 @@ 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} /* Extended quote * xqdouble implements embedded quote, '''' */ xqstart {quote} xqdouble {quote}{quote} -xqinside [^\\']+ -xqescape [\\][^0-7] -xqoctesc [\\][0-7]{1,3} -xqhexesc [\\]x[0-9A-Fa-f]{1,2} +xqinside [^']+ /* $foo$ style quotes ("dollar quoting") * The quoted string starts with $foo$ where "foo" is an optional string @@ -448,38 +451,44 @@ other . } {xqstart} { - BEGIN(xq); + if (standard_strings()) + BEGIN(xq); + else + BEGIN(xe); ECHO; } {xestart} { - BEGIN(xq); + BEGIN(xe); ECHO; } -<xq>{quotestop} | -<xq>{quotefail} { +<xq,xe>{quotestop} | +<xq,xe>{quotefail} { yyless(1); BEGIN(INITIAL); ECHO; } -<xq>{xqdouble} { +<xq,xe>{xqdouble} { ECHO; } <xq>{xqinside} { ECHO; } -<xq>{xqescape} { +<xe>{xeinside} { + ECHO; + } +<xe>{xeescape} { ECHO; } -<xq>{xqoctesc} { +<xe>{xeoctesc} { ECHO; } -<xq>{xqhexesc} { +<xe>{xehexesc} { ECHO; } -<xq>{quotecontinue} { +<xq,xe>{quotecontinue} { ECHO; } -<xq>. { +<xe>. { /* This is only needed for \ just before EOF */ ECHO; } @@ -858,13 +867,13 @@ other . "\\r" { appendPQExpBufferChar(output_buf, '\r'); } "\\f" { appendPQExpBufferChar(output_buf, '\f'); } -{xqoctesc} { +{xeoctesc} { /* octal case */ appendPQExpBufferChar(output_buf, (char) strtol(yytext + 1, NULL, 8)); } -{xqhexesc} { +{xehexesc} { /* hex case */ appendPQExpBufferChar(output_buf, (char) strtol(yytext + 2, NULL, 16)); @@ -1128,6 +1137,10 @@ psql_scan(PsqlScanState state, result = PSCAN_INCOMPLETE; *prompt = PROMPT_SINGLEQUOTE; break; + case xe: + result = PSCAN_INCOMPLETE; + *prompt = PROMPT_SINGLEQUOTE; + break; case xdolq: result = PSCAN_INCOMPLETE; *prompt = PROMPT_DOLLARQUOTE; |