Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ef0dcf0

Browse files
author
Michael Meskes
committed
Fixed incorrect argument handling in SET command if argument is a variable.
1 parent a3faf37 commit ef0dcf0

File tree

6 files changed

+82
-26
lines changed

6 files changed

+82
-26
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,10 @@ Wed, 04 Jun 2008 14:22:30 +0200
23662366
Tue, 24 Jun 2008 13:30:51 +0200
23672367

23682368
- Synced parser.
2369+
2370+
Tue, 19 Aug 2008 12:32:24 +0200
2371+
2372+
- Fixed incorrect argument handling in SET command if argument is a variable.
23692373
- Set pgtypes library version to 3.1.
23702374
- Set compat library version to 3.1.
23712375
- Set ecpg library version to 6.2.

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.369 2008/07/16 01:30:23 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.370 2008/08/19 10:40:32 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -1247,7 +1247,16 @@ iso_level: READ UNCOMMITTED { $$ = make_str("read uncommitted"); }
12471247
;
12481248

12491249
var_value: opt_boolean { $$ = $1; }
1250-
| AllConst { $$ = $1; }
1250+
| AllConst { /* we have to check for a variable here because it has to be
1251+
replaced with its value on the client side */
1252+
if ($1[1] == '$')
1253+
{
1254+
$$ = make_str("$0");
1255+
free($1);
1256+
}
1257+
else
1258+
$$ = $1;
1259+
}
12511260
| ColId { $$ = $1; }
12521261
;
12531262

src/interfaces/ecpg/test/expected/sql-show.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
int main(int argc, char* argv[]) {
2626
/* exec sql begin declare section */
27-
27+
2828

2929
#line 9 "show.pgc"
30-
char var [ 25 ] ;
30+
char var [ 25 ] = "public" ;
3131
/* exec sql end declare section */
3232
#line 10 "show.pgc"
3333

@@ -44,7 +44,9 @@ int main(int argc, char* argv[]) {
4444
#line 16 "show.pgc"
4545

4646

47-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path to 'public'", ECPGt_EOIT, ECPGt_EORT);
47+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path to $0",
48+
ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
49+
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
4850
#line 18 "show.pgc"
4951

5052
if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -66,7 +68,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
6668

6769
printf("Var: Search path: %s\n", var);
6870

69-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
71+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set search_path to 'public'", ECPGt_EOIT, ECPGt_EORT);
7072
#line 22 "show.pgc"
7173

7274
if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -75,7 +77,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
7577
if (sqlca.sqlcode < 0) sqlprint();}
7678
#line 22 "show.pgc"
7779

78-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show standard_conforming_strings", ECPGt_EOIT,
80+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show search_path", ECPGt_EOIT,
7981
ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
8082
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
8183
#line 23 "show.pgc"
@@ -86,9 +88,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
8688
if (sqlca.sqlcode < 0) sqlprint();}
8789
#line 23 "show.pgc"
8890

89-
printf("Var: Standard conforming strings: %s\n", var);
91+
printf("Var: Search path: %s\n", var);
9092

91-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set time zone PST8PDT", ECPGt_EOIT, ECPGt_EORT);
93+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
9294
#line 26 "show.pgc"
9395

9496
if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -97,7 +99,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
9799
if (sqlca.sqlcode < 0) sqlprint();}
98100
#line 26 "show.pgc"
99101

100-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show time zone", ECPGt_EOIT,
102+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show standard_conforming_strings", ECPGt_EOIT,
101103
ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
102104
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
103105
#line 27 "show.pgc"
@@ -108,9 +110,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
108110
if (sqlca.sqlcode < 0) sqlprint();}
109111
#line 27 "show.pgc"
110112

111-
printf("Time Zone: %s\n", var);
113+
printf("Var: Standard conforming strings: %s\n", var);
112114

113-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set transaction isolation level read committed", ECPGt_EOIT, ECPGt_EORT);
115+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set time zone PST8PDT", ECPGt_EOIT, ECPGt_EORT);
114116
#line 30 "show.pgc"
115117

116118
if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -119,7 +121,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
119121
if (sqlca.sqlcode < 0) sqlprint();}
120122
#line 30 "show.pgc"
121123

122-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show transaction isolation level", ECPGt_EOIT,
124+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show time zone", ECPGt_EOIT,
123125
ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
124126
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
125127
#line 31 "show.pgc"
@@ -130,9 +132,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
130132
if (sqlca.sqlcode < 0) sqlprint();}
131133
#line 31 "show.pgc"
132134

133-
printf("Transaction isolation level: %s\n", var);
135+
printf("Time Zone: %s\n", var);
134136

135-
{ ECPGdisconnect(__LINE__, "ALL");
137+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set transaction isolation level read committed", ECPGt_EOIT, ECPGt_EORT);
136138
#line 34 "show.pgc"
137139

138140
if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -141,6 +143,28 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
141143
if (sqlca.sqlcode < 0) sqlprint();}
142144
#line 34 "show.pgc"
143145

146+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "show transaction isolation level", ECPGt_EOIT,
147+
ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char),
148+
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
149+
#line 35 "show.pgc"
150+
151+
if (sqlca.sqlwarn[0] == 'W') sqlprint();
152+
#line 35 "show.pgc"
153+
154+
if (sqlca.sqlcode < 0) sqlprint();}
155+
#line 35 "show.pgc"
156+
157+
printf("Transaction isolation level: %s\n", var);
158+
159+
{ ECPGdisconnect(__LINE__, "ALL");
160+
#line 38 "show.pgc"
161+
162+
if (sqlca.sqlwarn[0] == 'W') sqlprint();
163+
#line 38 "show.pgc"
164+
165+
if (sqlca.sqlcode < 0) sqlprint();}
166+
#line 38 "show.pgc"
167+
144168

145169
return 0;
146170
}

src/interfaces/ecpg/test/expected/sql-show.stderr

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[NO_PID]: sqlca: code: 0, state: 00000
33
[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>
44
[NO_PID]: sqlca: code: 0, state: 00000
5-
[NO_PID]: ecpg_execute on line 18: query: set search_path to 'public'; with 0 parameter(s) on connection regress1
5+
[NO_PID]: ecpg_execute on line 18: query: set search_path to public; with 0 parameter(s) on connection regress1
66
[NO_PID]: sqlca: code: 0, state: 00000
77
[NO_PID]: ecpg_execute on line 18: using PQexec
88
[NO_PID]: sqlca: code: 0, state: 00000
@@ -16,47 +16,61 @@
1616
[NO_PID]: sqlca: code: 0, state: 00000
1717
[NO_PID]: ecpg_get_data on line 19: RESULT: public offset: -1; array: yes
1818
[NO_PID]: sqlca: code: 0, state: 00000
19-
[NO_PID]: ecpg_execute on line 22: query: set standard_conforming_strings to off; with 0 parameter(s) on connection regress1
19+
[NO_PID]: ecpg_execute on line 22: query: set search_path to 'public'; with 0 parameter(s) on connection regress1
2020
[NO_PID]: sqlca: code: 0, state: 00000
2121
[NO_PID]: ecpg_execute on line 22: using PQexec
2222
[NO_PID]: sqlca: code: 0, state: 00000
2323
[NO_PID]: ecpg_execute on line 22: OK: SET
2424
[NO_PID]: sqlca: code: 0, state: 00000
25-
[NO_PID]: ecpg_execute on line 23: query: show standard_conforming_strings; with 0 parameter(s) on connection regress1
25+
[NO_PID]: ecpg_execute on line 23: query: show search_path; with 0 parameter(s) on connection regress1
2626
[NO_PID]: sqlca: code: 0, state: 00000
2727
[NO_PID]: ecpg_execute on line 23: using PQexec
2828
[NO_PID]: sqlca: code: 0, state: 00000
2929
[NO_PID]: ecpg_execute on line 23: correctly got 1 tuples with 1 fields
3030
[NO_PID]: sqlca: code: 0, state: 00000
31-
[NO_PID]: ecpg_get_data on line 23: RESULT: off offset: -1; array: yes
31+
[NO_PID]: ecpg_get_data on line 23: RESULT: public offset: -1; array: yes
3232
[NO_PID]: sqlca: code: 0, state: 00000
33-
[NO_PID]: ecpg_execute on line 26: query: set time zone PST8PDT; with 0 parameter(s) on connection regress1
33+
[NO_PID]: ecpg_execute on line 26: query: set standard_conforming_strings to off; with 0 parameter(s) on connection regress1
3434
[NO_PID]: sqlca: code: 0, state: 00000
3535
[NO_PID]: ecpg_execute on line 26: using PQexec
3636
[NO_PID]: sqlca: code: 0, state: 00000
3737
[NO_PID]: ecpg_execute on line 26: OK: SET
3838
[NO_PID]: sqlca: code: 0, state: 00000
39-
[NO_PID]: ecpg_execute on line 27: query: show time zone; with 0 parameter(s) on connection regress1
39+
[NO_PID]: ecpg_execute on line 27: query: show standard_conforming_strings; with 0 parameter(s) on connection regress1
4040
[NO_PID]: sqlca: code: 0, state: 00000
4141
[NO_PID]: ecpg_execute on line 27: using PQexec
4242
[NO_PID]: sqlca: code: 0, state: 00000
4343
[NO_PID]: ecpg_execute on line 27: correctly got 1 tuples with 1 fields
4444
[NO_PID]: sqlca: code: 0, state: 00000
45-
[NO_PID]: ecpg_get_data on line 27: RESULT: PST8PDT offset: -1; array: yes
45+
[NO_PID]: ecpg_get_data on line 27: RESULT: off offset: -1; array: yes
4646
[NO_PID]: sqlca: code: 0, state: 00000
47-
[NO_PID]: ecpg_execute on line 30: query: set transaction isolation level read committed; with 0 parameter(s) on connection regress1
47+
[NO_PID]: ecpg_execute on line 30: query: set time zone PST8PDT; with 0 parameter(s) on connection regress1
4848
[NO_PID]: sqlca: code: 0, state: 00000
4949
[NO_PID]: ecpg_execute on line 30: using PQexec
5050
[NO_PID]: sqlca: code: 0, state: 00000
5151
[NO_PID]: ecpg_execute on line 30: OK: SET
5252
[NO_PID]: sqlca: code: 0, state: 00000
53-
[NO_PID]: ecpg_execute on line 31: query: show transaction isolation level; with 0 parameter(s) on connection regress1
53+
[NO_PID]: ecpg_execute on line 31: query: show time zone; with 0 parameter(s) on connection regress1
5454
[NO_PID]: sqlca: code: 0, state: 00000
5555
[NO_PID]: ecpg_execute on line 31: using PQexec
5656
[NO_PID]: sqlca: code: 0, state: 00000
5757
[NO_PID]: ecpg_execute on line 31: correctly got 1 tuples with 1 fields
5858
[NO_PID]: sqlca: code: 0, state: 00000
59-
[NO_PID]: ecpg_get_data on line 31: RESULT: read committed offset: -1; array: yes
59+
[NO_PID]: ecpg_get_data on line 31: RESULT: PST8PDT offset: -1; array: yes
60+
[NO_PID]: sqlca: code: 0, state: 00000
61+
[NO_PID]: ecpg_execute on line 34: query: set transaction isolation level read committed; with 0 parameter(s) on connection regress1
62+
[NO_PID]: sqlca: code: 0, state: 00000
63+
[NO_PID]: ecpg_execute on line 34: using PQexec
64+
[NO_PID]: sqlca: code: 0, state: 00000
65+
[NO_PID]: ecpg_execute on line 34: OK: SET
66+
[NO_PID]: sqlca: code: 0, state: 00000
67+
[NO_PID]: ecpg_execute on line 35: query: show transaction isolation level; with 0 parameter(s) on connection regress1
68+
[NO_PID]: sqlca: code: 0, state: 00000
69+
[NO_PID]: ecpg_execute on line 35: using PQexec
70+
[NO_PID]: sqlca: code: 0, state: 00000
71+
[NO_PID]: ecpg_execute on line 35: correctly got 1 tuples with 1 fields
72+
[NO_PID]: sqlca: code: 0, state: 00000
73+
[NO_PID]: ecpg_get_data on line 35: RESULT: read committed offset: -1; array: yes
6074
[NO_PID]: sqlca: code: 0, state: 00000
6175
[NO_PID]: ecpg_finish: connection regress1 closed
6276
[NO_PID]: sqlca: code: 0, state: 00000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Var: Search path: public
2+
Var: Search path: public
23
Var: Standard conforming strings: off
34
Time Zone: PST8PDT
45
Transaction isolation level: read committed

src/interfaces/ecpg/test/sql/show.pgc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ EXEC SQL INCLUDE ../regression;
66

77
int main(int argc, char* argv[]) {
88
EXEC SQL BEGIN DECLARE SECTION;
9-
char var[25];
9+
char var[25] = "public";
1010
EXEC SQL END DECLARE SECTION;
1111

1212
ECPGdebug(1, stderr);
@@ -15,6 +15,10 @@ int main(int argc, char* argv[]) {
1515
EXEC SQL WHENEVER SQLWARNING SQLPRINT;
1616
EXEC SQL WHENEVER SQLERROR SQLPRINT;
1717

18+
EXEC SQL SET search_path TO :var;
19+
EXEC SQL SHOW search_path INTO :var;
20+
printf("Var: Search path: %s\n", var);
21+
1822
EXEC SQL SET search_path TO 'public';
1923
EXEC SQL SHOW search_path INTO :var;
2024
printf("Var: Search path: %s\n", var);

0 commit comments

Comments
 (0)