Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf346a23

Browse files
author
Michael Meskes
committed
Fixed parsing of parameters. Added regression test for this.
1 parent84c3769 commitf346a23

File tree

7 files changed

+104
-23
lines changed

7 files changed

+104
-23
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,10 @@ Tue, 07 Oct 2008 14:35:26 +0200
23822382
Fri, 10 Oct 2008 14:03:05 +0200
23832383

23842384
- Fixed "create role" parsing to accept optional "with" argument.
2385+
2386+
Tue, 14 Oct 2008 11:25:51 +0200
2387+
2388+
- Fixed parameter parsing.
23852389
- Set pgtypes library version to 3.1.
23862390
- Set compat library version to 3.1.
23872391
- Set ecpg library version to 6.2.

‎src/interfaces/ecpg/preproc/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1998-2008, PostgreSQL Global Development Group
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.136 2008/08/29 13:02:32 petere Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.137 2008/10/14 09:31:04 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -55,7 +55,6 @@ endif
5555
ecpg_keywords.oc_keywords.okeywords.opreproc.oparser.o: preproc.h
5656

5757
# instead of maintaining our own list, take the one from the backend
58-
# we cannot just link it in, but must copy and make some minor changes
5958
keywords.c:% :$(top_srcdir)/src/backend/parser/%
6059
rm -f$@&&$(LN_S)$<.
6160

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.375 2008/10/10 12:17:18 meskes Exp $*/
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.376 2008/10/14 09:31:04 meskes Exp $*/
22

33
/* Copyright comment*/
44
%{
@@ -658,7 +658,7 @@ add_typedef(char *name, char * dimension, char * length, enum ECPGttype type_enu
658658
%type<str>AlterOwnerStmtOptTableSpaceOwnerCreateTableSpaceStmt
659659
%type<str>DropTableSpaceStmtindirectionindirection_elECPGSetDescriptorHeader
660660
%type<str>AlterDatabaseStmtCreateRoleStmtOptRoleListAlterRoleStmtAlterRoleSetStmt
661-
%type<str>DropRoleStmtadd_dropopt_validatorcommon_func_opt_item
661+
%type<str>DropRoleStmtadd_dropopt_validatorcommon_func_opt_itemParam
662662
%type<str>opt_grant_admin_optionAlterFunctionStmtalterfunc_opt_listopt_restrict
663663
%type<str>AlterObjectSchemaStmtalterdb_opt_listfor_locking_clauseopt_for_locking_clause
664664
%type<str>locked_rels_listopt_granted_byRevokeRoleStmtalterdb_opt_itemusing_clause
@@ -3939,7 +3939,7 @@ where_clause: WHERE a_expr{ $$ = cat2_str(make_str("where"), $2); }
39393939

39403940
where_or_current_clause:WHEREa_expr{$$ = cat2_str(make_str("where"),$2); }
39413941
|WHERECURRENT_POFname{$$ = cat2_str(make_str("where current of"),$4); }
3942-
|WHERECURRENT_POFPARAM{$$ = make_str("where current of param"); }
3942+
|WHERECURRENT_POFParam{$$ =cat2_str(make_str("where current of"),$4); }
39433943
|/*EMPTY*/{$$ = EMPTY;/* no qualifiers*/ }
39443944
;
39453945

@@ -4397,8 +4397,8 @@ c_expr: columnref
43974397
{$$ =$1;}
43984398
|AexprConst
43994399
{$$ =$1;}
4400-
|PARAMopt_indirection
4401-
{$$ = cat2_str(make_str("param"),$2); }
4400+
|Paramopt_indirection
4401+
{$$ = cat2_str($1,$2); }
44024402
|'('a_expr')'opt_indirection
44034403
{$$ = cat_str(4, make_str("("),$2, make_str(")"),$4); }
44044404
|case_expr
@@ -4920,6 +4920,7 @@ AexprConst: PosAllConst
49204920
{$$ =$1; }
49214921
;
49224922

4923+
Param:PARAM{$$ = make_name();};
49234924
Iconst:ICONST{$$ = make_name();};
49244925
Fconst:FCONST{$$ = make_name();};
49254926
Bconst:BCONST{$$ = make_name();};

‎src/interfaces/ecpg/test/expected/sql-fetch.c

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,34 +162,72 @@ if (sqlca.sqlcode < 0) sqlprint();}
162162

163163
printf("%d: %s\n",i,str);
164164

165-
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"close C",ECPGt_EOIT,ECPGt_EORT);
165+
/* declare D cursor for select * from My_Table where Item1 = $1 */
166166
#line 42 "fetch.pgc"
167167

168+
169+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"declare D cursor for select * from My_Table where Item1 = $1 ",
170+
ECPGt_const,"1",(long)1,(long)1,strlen("1"),
171+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EOIT,ECPGt_EORT);
172+
#line 44 "fetch.pgc"
173+
168174
if (sqlca.sqlwarn[0]=='W')sqlprint();
169-
#line42 "fetch.pgc"
175+
#line44 "fetch.pgc"
170176

171177
if (sqlca.sqlcode<0)sqlprint();}
172-
#line 42 "fetch.pgc"
178+
#line 44 "fetch.pgc"
179+
180+
181+
/* exec sql whenever not found break ; */
182+
#line 46 "fetch.pgc"
183+
184+
while (1) {
185+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch 1 in D",ECPGt_EOIT,
186+
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
187+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,
188+
ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char),
189+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
190+
#line 48 "fetch.pgc"
191+
192+
if (sqlca.sqlcode==ECPG_NOT_FOUND)break;
193+
#line 48 "fetch.pgc"
194+
195+
if (sqlca.sqlwarn[0]=='W')sqlprint();
196+
#line 48 "fetch.pgc"
197+
198+
if (sqlca.sqlcode<0)sqlprint();}
199+
#line 48 "fetch.pgc"
200+
201+
printf("%d: %s\n",i,str);
202+
}
203+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"close D",ECPGt_EOIT,ECPGt_EORT);
204+
#line 51 "fetch.pgc"
205+
206+
if (sqlca.sqlwarn[0]=='W')sqlprint();
207+
#line 51 "fetch.pgc"
208+
209+
if (sqlca.sqlcode<0)sqlprint();}
210+
#line 51 "fetch.pgc"
173211

174212

175213
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"drop table My_Table ",ECPGt_EOIT,ECPGt_EORT);
176-
#line44 "fetch.pgc"
214+
#line53 "fetch.pgc"
177215

178216
if (sqlca.sqlwarn[0]=='W')sqlprint();
179-
#line44 "fetch.pgc"
217+
#line53 "fetch.pgc"
180218

181219
if (sqlca.sqlcode<0)sqlprint();}
182-
#line44 "fetch.pgc"
220+
#line53 "fetch.pgc"
183221

184222

185223
{ECPGdisconnect(__LINE__,"ALL");
186-
#line46 "fetch.pgc"
224+
#line55 "fetch.pgc"
187225

188226
if (sqlca.sqlwarn[0]=='W')sqlprint();
189-
#line46 "fetch.pgc"
227+
#line55 "fetch.pgc"
190228

191229
if (sqlca.sqlcode<0)sqlprint();}
192-
#line46 "fetch.pgc"
230+
#line55 "fetch.pgc"
193231

194232

195233
return0;

‎src/interfaces/ecpg/test/expected/sql-fetch.stderr

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,46 @@
102102
[NO_PID]: sqlca: code: 0, state: 00000
103103
[NO_PID]: ecpg_get_data on line 39: RESULT: text4 offset: -1; array: yes
104104
[NO_PID]: sqlca: code: 0, state: 00000
105-
[NO_PID]: ecpg_execute on line42: query:close C; with0 parameter(s) on connection regress1
105+
[NO_PID]: ecpg_execute on line44: query:declare D cursor for select * from My_Table where Item1 = $1; with1 parameter(s) on connection regress1
106106
[NO_PID]: sqlca: code: 0, state: 00000
107-
[NO_PID]: ecpg_execute on line42: usingPQexec
107+
[NO_PID]: ecpg_execute on line44: usingPQexecParams
108108
[NO_PID]: sqlca: code: 0, state: 00000
109-
[NO_PID]:ecpg_execute on line42: OK: CLOSE CURSOR
109+
[NO_PID]:free_params on line44: parameter 1 = 1
110110
[NO_PID]: sqlca: code: 0, state: 00000
111-
[NO_PID]: ecpg_execute on line 44:query: drop table My_Table ; with 0 parameter(s) on connection regress1
111+
[NO_PID]: ecpg_execute on line 44:OK: DECLARE CURSOR
112112
[NO_PID]: sqlca: code: 0, state: 00000
113-
[NO_PID]: ecpg_execute on line44: using PQexec
113+
[NO_PID]: ecpg_execute on line48: query: fetch 1 in D; with 0 parameter(s) on connection regress1
114114
[NO_PID]: sqlca: code: 0, state: 00000
115-
[NO_PID]: ecpg_execute on line44: OK: DROP TABLE
115+
[NO_PID]: ecpg_execute on line48: using PQexec
116116
[NO_PID]: sqlca: code: 0, state: 00000
117+
[NO_PID]: ecpg_execute on line 48: correctly got 1 tuples with 2 fields
118+
[NO_PID]: sqlca: code: 0, state: 00000
119+
[NO_PID]: ecpg_get_data on line 48: RESULT: 1 offset: -1; array: yes
120+
[NO_PID]: sqlca: code: 0, state: 00000
121+
[NO_PID]: ecpg_get_data on line 48: RESULT: text1 offset: -1; array: yes
122+
[NO_PID]: sqlca: code: 0, state: 00000
123+
[NO_PID]: ecpg_execute on line 48: query: fetch 1 in D; with 0 parameter(s) on connection regress1
124+
[NO_PID]: sqlca: code: 0, state: 00000
125+
[NO_PID]: ecpg_execute on line 48: using PQexec
126+
[NO_PID]: sqlca: code: 0, state: 00000
127+
[NO_PID]: ecpg_execute on line 48: correctly got 0 tuples with 2 fields
128+
[NO_PID]: sqlca: code: 0, state: 00000
129+
[NO_PID]: raising sqlcode 100 on line 48: no data found on line 48
130+
[NO_PID]: sqlca: code: 100, state: 02000
131+
[NO_PID]: ecpg_execute on line 51: query: close D; with 0 parameter(s) on connection regress1
132+
[NO_PID]: sqlca: code: 0, state: 00000
133+
[NO_PID]: ecpg_execute on line 51: using PQexec
134+
[NO_PID]: sqlca: code: 0, state: 00000
135+
[NO_PID]: ecpg_execute on line 51: OK: CLOSE CURSOR
136+
[NO_PID]: sqlca: code: 0, state: 00000
137+
[NO_PID]: ecpg_execute on line 53: query: drop table My_Table ; with 0 parameter(s) on connection regress1
138+
[NO_PID]: sqlca: code: 0, state: 00000
139+
[NO_PID]: ecpg_execute on line 53: using PQexec
140+
[NO_PID]: sqlca: code: 0, state: 00000
141+
[NO_PID]: ecpg_check_PQresult on line 53: ERROR: relation 16491 is still open
142+
[NO_PID]: sqlca: code: 0, state: 00000
143+
[NO_PID]: raising sqlstate XX000 (sqlcode -400) on line 53: relation 16491 is still open on line 53
144+
[NO_PID]: sqlca: code: -400, state: XX000
145+
sql error: relation 16491 is still open on line 53
117146
[NO_PID]: ecpg_finish: connection regress1 closed
118147
[NO_PID]: sqlca: code: 0, state: 00000

‎src/interfaces/ecpg/test/expected/sql-fetch.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
3: text3
44
4: text4
55
4: text4
6+
1: text1

‎src/interfaces/ecpg/test/sql/fetch.pgc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ int main(int argc, char* argv[]) {
3939
EXEC SQL FETCH :count IN C INTO :i, :str;
4040
printf("%d: %s\n", i, str);
4141

42-
EXEC SQL CLOSE C;
42+
EXEC SQL DECLARE D CURSOR FOR SELECT * FROM My_Table WHERE Item1 = $1;
43+
44+
EXEC SQL OPEN D using 1;
45+
46+
EXEC SQL WHENEVER NOT FOUND DO BREAK;
47+
while (1) {
48+
EXEC SQL FETCH 1 IN D INTO :i, :str;
49+
printf("%d: %s\n", i, str);
50+
}
51+
EXEC SQL CLOSE D;
4352

4453
EXEC SQL DROP TABLE My_Table;
4554

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp