]> granicus.if.org Git - postgresql/commitdiff
Fixed incorrect argument handling in SET command if argument is a variable.
authorMichael Meskes <meskes@postgresql.org>
Tue, 19 Aug 2008 10:40:32 +0000 (10:40 +0000)
committerMichael Meskes <meskes@postgresql.org>
Tue, 19 Aug 2008 10:40:32 +0000 (10:40 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/test/expected/sql-show.c
src/interfaces/ecpg/test/expected/sql-show.stderr
src/interfaces/ecpg/test/expected/sql-show.stdout
src/interfaces/ecpg/test/sql/show.pgc

index e801b1a6a56c9bde0eeb4e48aa1ee4f2e70e0a3e..f5e14af46b481c50845672734ff8e663546c0c3b 100644 (file)
@@ -2366,6 +2366,10 @@ Wed, 04 Jun 2008 14:22:30 +0200
 Tue, 24 Jun 2008 13:30:51 +0200
 
        - Synced parser.
+
+Tue, 19 Aug 2008 12:32:24 +0200
+
+       - Fixed incorrect argument handling in SET command if argument is a variable.
        - Set pgtypes library version to 3.1.
        - Set compat library version to 3.1.
        - Set ecpg library version to 6.2.
index 73ad1a577b862c637592de5567b7204e6529932c..884fbeecbec2be5a30c0182811ff0c50b7b8bc0e 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.369 2008/07/16 01:30:23 tgl Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.370 2008/08/19 10:40:32 meskes Exp $ */
 
 /* Copyright comment */
 %{
@@ -1247,7 +1247,16 @@ iso_level:       READ UNCOMMITTED        { $$ = make_str("read uncommitted"); }
                ;
 
 var_value:     opt_boolean             { $$ = $1; }
-               | AllConst                      { $$ = $1; }
+               | AllConst                      {       /* we have to check for a variable here because it has to be
+                                                       replaced with its value on the client side */
+                                                       if ($1[1] == '$')
+                                                       {
+                                                               $$ = make_str("$0");
+                                                               free($1);
+                                                       }
+                                                       else
+                                                               $$ = $1;
+                                               }
                | ColId                         { $$ = $1; }
                ;
 
index 3433d30b09692c13b4e59777669cea86ec57b887..daac722339320d70958fb92852b07bd117ec25eb 100644 (file)
 
 int main(int argc, char* argv[]) {
   /* exec sql begin declare section */
-     
+       
   
 #line 9 "show.pgc"
- char  var [ 25 ]    ;
+ char  var [ 25 ]   = "public" ;
 /* exec sql end declare section */
 #line 10 "show.pgc"
 
@@ -44,7 +44,9 @@ int main(int argc, char* argv[]) {
 #line 16 "show.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path to 'public'", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path to $0", 
+       ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
+       ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 18 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -66,7 +68,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
   printf("Var: Search path: %s\n", var);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path to 'public'", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -75,7 +77,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 22 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show standard_conforming_strings", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show search_path", ECPGt_EOIT, 
        ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 23 "show.pgc"
@@ -86,9 +88,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 23 "show.pgc"
 
-  printf("Var: Standard conforming strings: %s\n", var);
+  printf("Var: Search path: %s\n", var);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set time zone PST8PDT", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
 #line 26 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -97,7 +99,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 26 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show time zone", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show standard_conforming_strings", ECPGt_EOIT, 
        ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 27 "show.pgc"
@@ -108,9 +110,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 27 "show.pgc"
 
-  printf("Time Zone: %s\n", var);
+  printf("Var: Standard conforming strings: %s\n", var);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set transaction isolation level read committed", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set time zone PST8PDT", ECPGt_EOIT, ECPGt_EORT);
 #line 30 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -119,7 +121,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 30 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show transaction isolation level", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show time zone", ECPGt_EOIT, 
        ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 31 "show.pgc"
@@ -130,9 +132,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 31 "show.pgc"
 
-  printf("Transaction isolation level: %s\n", var);
+  printf("Time Zone: %s\n", var);
 
-  { ECPGdisconnect(__LINE__, "ALL");
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set transaction isolation level read committed", ECPGt_EOIT, ECPGt_EORT);
 #line 34 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -141,6 +143,28 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 34 "show.pgc"
 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show transaction isolation level", ECPGt_EOIT, 
+       ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
+       ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 35 "show.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 35 "show.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 35 "show.pgc"
+
+  printf("Transaction isolation level: %s\n", var);
+
+  { ECPGdisconnect(__LINE__, "ALL");
+#line 38 "show.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 38 "show.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 38 "show.pgc"
+
 
   return 0;
 }
index 44634d91732219fec9ea7ff2ccf784cd5a661c00..b176903c2096cdf040e8c814576b51b09cfd4c09 100644 (file)
@@ -2,7 +2,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>  
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 18: query: set search_path to 'public'; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 18: query: set search_path to public; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 18: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_get_data on line 19: RESULT: public offset: -1; array: yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 22: query: set standard_conforming_strings to off; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 22: query: set search_path to 'public'; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 22: OK: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 23: query: show standard_conforming_strings; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 23: query: show search_path; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 23: correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 23: RESULT: off offset: -1; array: yes
+[NO_PID]: ecpg_get_data on line 23: RESULT: public offset: -1; array: yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 26: query: set time zone PST8PDT; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 26: query: set standard_conforming_strings to off; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 26: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 26: OK: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 27: query: show time zone; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 27: query: show standard_conforming_strings; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 27: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 27: correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 27: RESULT: PST8PDT offset: -1; array: yes
+[NO_PID]: ecpg_get_data on line 27: RESULT: off offset: -1; array: yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 30: query: set transaction isolation level read committed; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 30: query: set time zone PST8PDT; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 30: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 30: OK: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_execute on line 31: query: show transaction isolation level; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 31: query: show time zone; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 31: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_execute on line 31: correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_get_data on line 31: RESULT: read committed offset: -1; array: yes
+[NO_PID]: ecpg_get_data on line 31: RESULT: PST8PDT offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 34: query: set transaction isolation level read committed; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 34: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 34: OK: SET
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 35: query: show transaction isolation level; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 35: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 35: correctly got 1 tuples with 1 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 35: RESULT: read committed offset: -1; array: yes
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection regress1 closed
 [NO_PID]: sqlca: code: 0, state: 00000
index 76f854b040da1d4c3d22d0826b1a07e1c47a42a8..9319c5d113580faa750ecdb35c0c1aaa5c17d8a6 100644 (file)
@@ -1,4 +1,5 @@
 Var: Search path: public
+Var: Search path: public
 Var: Standard conforming strings: off
 Time Zone: PST8PDT
 Transaction isolation level: read committed
index 8eb71a7262a436af6ca2197b5264529a5f4b4549..d3a888d5095ccc11a1ecc3eeb86205852507b04d 100644 (file)
@@ -6,7 +6,7 @@ EXEC SQL INCLUDE ../regression;
 
 int main(int argc, char* argv[]) {
   EXEC SQL BEGIN DECLARE SECTION;
-    char var[25];
+    char var[25] = "public";
   EXEC SQL END DECLARE SECTION;
 
   ECPGdebug(1, stderr);
@@ -15,6 +15,10 @@ int main(int argc, char* argv[]) {
   EXEC SQL WHENEVER SQLWARNING SQLPRINT;
   EXEC SQL WHENEVER SQLERROR SQLPRINT;
 
+  EXEC SQL SET search_path TO :var;
+  EXEC SQL SHOW search_path INTO :var;
+  printf("Var: Search path: %s\n", var);
+
   EXEC SQL SET search_path TO 'public';
   EXEC SQL SHOW search_path INTO :var;
   printf("Var: Search path: %s\n", var);