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

Commitd22e9d5

Browse files
author
Michael Meskes
committed
Implement DO CONTINUE action for ECPG WHENEVER statement.
Author: Vinayak PokaleReviewed-By: Masahiko Sawada
1 parent3f4c791 commitd22e9d5

File tree

9 files changed

+361
-0
lines changed

9 files changed

+361
-0
lines changed

‎doc/src/sgml/ecpg.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4762,6 +4762,17 @@ EXEC SQL WHENEVER <replaceable>condition</replaceable> <replaceable>action</repl
47624762
</listitem>
47634763
</varlistentry>
47644764

4765+
<varlistentry>
4766+
<term><literal>DO CONTINUE</literal></term>
4767+
<listitem>
4768+
<para>
4769+
Execute the C statement <literal>continue</literal>. This should
4770+
only be used in loops statements. if executed, will cause the flow
4771+
of control to return to the top of the loop.
4772+
</para>
4773+
</listitem>
4774+
</varlistentry>
4775+
47654776
<varlistentry>
47664777
<term><literal>CALL <replaceable>name</replaceable> (<replaceable>args</replaceable>)</literal></term>
47674778
<term><literal>DO <replaceable>name</replaceable> (<replaceable>args</replaceable>)</literal></term>
@@ -7799,6 +7810,7 @@ WHENEVER { NOT FOUND | SQLERROR | SQLWARNING } <replaceable class="PARAMETER">ac
77997810
<programlisting>
78007811
EXEC SQL WHENEVER NOT FOUND CONTINUE;
78017812
EXEC SQL WHENEVER NOT FOUND DO BREAK;
7813+
EXEC SQL WHENEVER NOT FOUND DO CONTINUE;
78027814
EXEC SQL WHENEVER SQLWARNING SQLPRINT;
78037815
EXEC SQL WHENEVER SQLWARNING DO warn();
78047816
EXEC SQL WHENEVER SQLERROR sqlprint;

‎src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,12 @@ action : CONTINUE_P
14541454
$<action>$.command = NULL;
14551455
$<action>$.str = mm_strdup("break");
14561456
}
1457+
| DO CONTINUE_P
1458+
{
1459+
$<action>$.code = W_CONTINUE;
1460+
$<action>$.command = NULL;
1461+
$<action>$.str = mm_strdup("continue");
1462+
}
14571463
| SQL_CALL name '(' c_args ')'
14581464
{
14591465
$<action>$.code = W_DO;

‎src/interfaces/ecpg/preproc/output.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ print_action(struct when *w)
5151
caseW_BREAK:
5252
fprintf(base_yyout,"break;");
5353
break;
54+
caseW_CONTINUE:
55+
fprintf(base_yyout,"continue;");
56+
break;
5457
default:
5558
fprintf(base_yyout,"{/* %d not implemented yet */}",w->code);
5659
break;

‎src/interfaces/ecpg/test/ecpg_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ test: preproc/type
2828
test: preproc/variable
2929
test: preproc/outofscope
3030
test: preproc/whenever
31+
test: preproc/whenever_do_continue
3132
test: sql/array
3233
test: sql/binary
3334
test: sql/code100
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/* Processed by ecpg (regression mode) */
2+
/* These include files are added by the preprocessor */
3+
#include<ecpglib.h>
4+
#include<ecpgerrno.h>
5+
#include<sqlca.h>
6+
/* End of automatic include section */
7+
#defineECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8+
9+
#line 1 "whenever_do_continue.pgc"
10+
#include<stdlib.h>
11+
12+
13+
#line 1 "regression.h"
14+
15+
16+
17+
18+
19+
20+
#line 3 "whenever_do_continue.pgc"
21+
22+
23+
/* exec sql whenever sqlerror sqlprint ; */
24+
#line 5 "whenever_do_continue.pgc"
25+
26+
27+
intmain(void)
28+
{
29+
/* exec sql begin declare section */
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
#line 15 "whenever_do_continue.pgc"
40+
struct {
41+
#line 12 "whenever_do_continue.pgc"
42+
charename [12 ] ;
43+
44+
#line 13 "whenever_do_continue.pgc"
45+
floatsal ;
46+
47+
#line 14 "whenever_do_continue.pgc"
48+
floatcomm ;
49+
}emp ;
50+
51+
#line 17 "whenever_do_continue.pgc"
52+
charmsg [128 ] ;
53+
/* exec sql end declare section */
54+
#line 18 "whenever_do_continue.pgc"
55+
56+
57+
ECPGdebug(1,stderr);
58+
59+
strcpy(msg,"connect");
60+
{ECPGconnect(__LINE__,0,"ecpg1_regression" ,NULL,NULL ,NULL,0);
61+
#line 23 "whenever_do_continue.pgc"
62+
63+
if (sqlca.sqlcode<0)sqlprint();}
64+
#line 23 "whenever_do_continue.pgc"
65+
66+
67+
strcpy(msg,"create");
68+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"create table emp ( ename varchar , sal double precision , comm double precision )",ECPGt_EOIT,ECPGt_EORT);
69+
#line 26 "whenever_do_continue.pgc"
70+
71+
if (sqlca.sqlcode<0)sqlprint();}
72+
#line 26 "whenever_do_continue.pgc"
73+
74+
75+
strcpy(msg,"insert");
76+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into emp values ( 'Ram' , 111100 , 21 )",ECPGt_EOIT,ECPGt_EORT);
77+
#line 29 "whenever_do_continue.pgc"
78+
79+
if (sqlca.sqlcode<0)sqlprint();}
80+
#line 29 "whenever_do_continue.pgc"
81+
82+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into emp values ( 'aryan' , 11110 , null )",ECPGt_EOIT,ECPGt_EORT);
83+
#line 30 "whenever_do_continue.pgc"
84+
85+
if (sqlca.sqlcode<0)sqlprint();}
86+
#line 30 "whenever_do_continue.pgc"
87+
88+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into emp values ( 'josh' , 10000 , 10 )",ECPGt_EOIT,ECPGt_EORT);
89+
#line 31 "whenever_do_continue.pgc"
90+
91+
if (sqlca.sqlcode<0)sqlprint();}
92+
#line 31 "whenever_do_continue.pgc"
93+
94+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"insert into emp values ( 'tom' , 20000 , null )",ECPGt_EOIT,ECPGt_EORT);
95+
#line 32 "whenever_do_continue.pgc"
96+
97+
if (sqlca.sqlcode<0)sqlprint();}
98+
#line 32 "whenever_do_continue.pgc"
99+
100+
101+
/* declare c cursor for select ename , sal , comm from emp order by ename asc */
102+
#line 34 "whenever_do_continue.pgc"
103+
104+
105+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"declare c cursor for select ename , sal , comm from emp order by ename asc",ECPGt_EOIT,ECPGt_EORT);
106+
#line 36 "whenever_do_continue.pgc"
107+
108+
if (sqlca.sqlcode<0)sqlprint();}
109+
#line 36 "whenever_do_continue.pgc"
110+
111+
112+
/* The 'BREAK' condition to exit the loop. */
113+
/* exec sql whenever not found break ; */
114+
#line 39 "whenever_do_continue.pgc"
115+
116+
117+
/* The DO CONTINUE makes the loop start at the next iteration when an error occurs.*/
118+
/* exec sql whenever sqlerror continue ; */
119+
#line 42 "whenever_do_continue.pgc"
120+
121+
122+
while (1)
123+
{
124+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch c",ECPGt_EOIT,
125+
ECPGt_char,&(emp.ename),(long)12,(long)1,(12)*sizeof(char),
126+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,
127+
ECPGt_float,&(emp.sal),(long)1,(long)1,sizeof(float),
128+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,
129+
ECPGt_float,&(emp.comm),(long)1,(long)1,sizeof(float),
130+
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);
131+
#line 46 "whenever_do_continue.pgc"
132+
133+
if (sqlca.sqlcode==ECPG_NOT_FOUND)break;
134+
#line 46 "whenever_do_continue.pgc"
135+
136+
if (sqlca.sqlcode<0)continue;}
137+
#line 46 "whenever_do_continue.pgc"
138+
139+
/* The employees with non-NULL commissions will be displayed. */
140+
printf("%s %7.2f %9.2f\n",emp.ename,emp.sal,emp.comm);
141+
}
142+
143+
/*
144+
* This 'CONTINUE' shuts off the 'DO CONTINUE' and allow the program to
145+
* proceed if any further errors do occur.
146+
*/
147+
/* exec sql whenever sqlerror continue ; */
148+
#line 55 "whenever_do_continue.pgc"
149+
150+
151+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"close c",ECPGt_EOIT,ECPGt_EORT);}
152+
#line 57 "whenever_do_continue.pgc"
153+
154+
155+
strcpy(msg,"drop");
156+
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"drop table emp",ECPGt_EOIT,ECPGt_EORT);}
157+
#line 60 "whenever_do_continue.pgc"
158+
159+
160+
exit(0);
161+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
[NO_PID]: ECPGdebug: set to 1
2+
[NO_PID]: sqlca: code: 0, state: 00000
3+
[NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
4+
[NO_PID]: sqlca: code: 0, state: 00000
5+
[NO_PID]: ecpg_execute on line 26: query: create table emp ( ename varchar , sal double precision , comm double precision ); with 0 parameter(s) on connection ecpg1_regression
6+
[NO_PID]: sqlca: code: 0, state: 00000
7+
[NO_PID]: ecpg_execute on line 26: using PQexec
8+
[NO_PID]: sqlca: code: 0, state: 00000
9+
[NO_PID]: ecpg_process_output on line 26: OK: CREATE TABLE
10+
[NO_PID]: sqlca: code: 0, state: 00000
11+
[NO_PID]: ecpg_execute on line 29: query: insert into emp values ( 'Ram' , 111100 , 21 ); with 0 parameter(s) on connection ecpg1_regression
12+
[NO_PID]: sqlca: code: 0, state: 00000
13+
[NO_PID]: ecpg_execute on line 29: using PQexec
14+
[NO_PID]: sqlca: code: 0, state: 00000
15+
[NO_PID]: ecpg_process_output on line 29: OK: INSERT 0 1
16+
[NO_PID]: sqlca: code: 0, state: 00000
17+
[NO_PID]: ecpg_execute on line 30: query: insert into emp values ( 'aryan' , 11110 , null ); with 0 parameter(s) on connection ecpg1_regression
18+
[NO_PID]: sqlca: code: 0, state: 00000
19+
[NO_PID]: ecpg_execute on line 30: using PQexec
20+
[NO_PID]: sqlca: code: 0, state: 00000
21+
[NO_PID]: ecpg_process_output on line 30: OK: INSERT 0 1
22+
[NO_PID]: sqlca: code: 0, state: 00000
23+
[NO_PID]: ecpg_execute on line 31: query: insert into emp values ( 'josh' , 10000 , 10 ); with 0 parameter(s) on connection ecpg1_regression
24+
[NO_PID]: sqlca: code: 0, state: 00000
25+
[NO_PID]: ecpg_execute on line 31: using PQexec
26+
[NO_PID]: sqlca: code: 0, state: 00000
27+
[NO_PID]: ecpg_process_output on line 31: OK: INSERT 0 1
28+
[NO_PID]: sqlca: code: 0, state: 00000
29+
[NO_PID]: ecpg_execute on line 32: query: insert into emp values ( 'tom' , 20000 , null ); with 0 parameter(s) on connection ecpg1_regression
30+
[NO_PID]: sqlca: code: 0, state: 00000
31+
[NO_PID]: ecpg_execute on line 32: using PQexec
32+
[NO_PID]: sqlca: code: 0, state: 00000
33+
[NO_PID]: ecpg_process_output on line 32: OK: INSERT 0 1
34+
[NO_PID]: sqlca: code: 0, state: 00000
35+
[NO_PID]: ecpg_execute on line 36: query: declare c cursor for select ename , sal , comm from emp order by ename asc; with 0 parameter(s) on connection ecpg1_regression
36+
[NO_PID]: sqlca: code: 0, state: 00000
37+
[NO_PID]: ecpg_execute on line 36: using PQexec
38+
[NO_PID]: sqlca: code: 0, state: 00000
39+
[NO_PID]: ecpg_process_output on line 36: OK: DECLARE CURSOR
40+
[NO_PID]: sqlca: code: 0, state: 00000
41+
[NO_PID]: ecpg_execute on line 46: query: fetch c; with 0 parameter(s) on connection ecpg1_regression
42+
[NO_PID]: sqlca: code: 0, state: 00000
43+
[NO_PID]: ecpg_execute on line 46: using PQexec
44+
[NO_PID]: sqlca: code: 0, state: 00000
45+
[NO_PID]: ecpg_process_output on line 46: correctly got 1 tuples with 3 fields
46+
[NO_PID]: sqlca: code: 0, state: 00000
47+
[NO_PID]: ecpg_get_data on line 46: RESULT: aryan offset: -1; array: no
48+
[NO_PID]: sqlca: code: 0, state: 00000
49+
[NO_PID]: ecpg_get_data on line 46: RESULT: 11110 offset: -1; array: no
50+
[NO_PID]: sqlca: code: 0, state: 00000
51+
[NO_PID]: ecpg_get_data on line 46: RESULT: offset: -1; array: no
52+
[NO_PID]: sqlca: code: 0, state: 00000
53+
[NO_PID]: raising sqlcode -213 on line 46: null value without indicator on line 46
54+
[NO_PID]: sqlca: code: -213, state: 22002
55+
[NO_PID]: ecpg_execute on line 46: query: fetch c; with 0 parameter(s) on connection ecpg1_regression
56+
[NO_PID]: sqlca: code: 0, state: 00000
57+
[NO_PID]: ecpg_execute on line 46: using PQexec
58+
[NO_PID]: sqlca: code: 0, state: 00000
59+
[NO_PID]: ecpg_process_output on line 46: correctly got 1 tuples with 3 fields
60+
[NO_PID]: sqlca: code: 0, state: 00000
61+
[NO_PID]: ecpg_get_data on line 46: RESULT: josh offset: -1; array: no
62+
[NO_PID]: sqlca: code: 0, state: 00000
63+
[NO_PID]: ecpg_get_data on line 46: RESULT: 10000 offset: -1; array: no
64+
[NO_PID]: sqlca: code: 0, state: 00000
65+
[NO_PID]: ecpg_get_data on line 46: RESULT: 10 offset: -1; array: no
66+
[NO_PID]: sqlca: code: 0, state: 00000
67+
[NO_PID]: ecpg_execute on line 46: query: fetch c; with 0 parameter(s) on connection ecpg1_regression
68+
[NO_PID]: sqlca: code: 0, state: 00000
69+
[NO_PID]: ecpg_execute on line 46: using PQexec
70+
[NO_PID]: sqlca: code: 0, state: 00000
71+
[NO_PID]: ecpg_process_output on line 46: correctly got 1 tuples with 3 fields
72+
[NO_PID]: sqlca: code: 0, state: 00000
73+
[NO_PID]: ecpg_get_data on line 46: RESULT: Ram offset: -1; array: no
74+
[NO_PID]: sqlca: code: 0, state: 00000
75+
[NO_PID]: ecpg_get_data on line 46: RESULT: 111100 offset: -1; array: no
76+
[NO_PID]: sqlca: code: 0, state: 00000
77+
[NO_PID]: ecpg_get_data on line 46: RESULT: 21 offset: -1; array: no
78+
[NO_PID]: sqlca: code: 0, state: 00000
79+
[NO_PID]: ecpg_execute on line 46: query: fetch c; with 0 parameter(s) on connection ecpg1_regression
80+
[NO_PID]: sqlca: code: 0, state: 00000
81+
[NO_PID]: ecpg_execute on line 46: using PQexec
82+
[NO_PID]: sqlca: code: 0, state: 00000
83+
[NO_PID]: ecpg_process_output on line 46: correctly got 1 tuples with 3 fields
84+
[NO_PID]: sqlca: code: 0, state: 00000
85+
[NO_PID]: ecpg_get_data on line 46: RESULT: tom offset: -1; array: no
86+
[NO_PID]: sqlca: code: 0, state: 00000
87+
[NO_PID]: ecpg_get_data on line 46: RESULT: 20000 offset: -1; array: no
88+
[NO_PID]: sqlca: code: 0, state: 00000
89+
[NO_PID]: ecpg_get_data on line 46: RESULT: offset: -1; array: no
90+
[NO_PID]: sqlca: code: 0, state: 00000
91+
[NO_PID]: raising sqlcode -213 on line 46: null value without indicator on line 46
92+
[NO_PID]: sqlca: code: -213, state: 22002
93+
[NO_PID]: ecpg_execute on line 46: query: fetch c; with 0 parameter(s) on connection ecpg1_regression
94+
[NO_PID]: sqlca: code: 0, state: 00000
95+
[NO_PID]: ecpg_execute on line 46: using PQexec
96+
[NO_PID]: sqlca: code: 0, state: 00000
97+
[NO_PID]: ecpg_process_output on line 46: correctly got 0 tuples with 3 fields
98+
[NO_PID]: sqlca: code: 0, state: 00000
99+
[NO_PID]: raising sqlcode 100 on line 46: no data found on line 46
100+
[NO_PID]: sqlca: code: 100, state: 02000
101+
[NO_PID]: ecpg_execute on line 57: query: close c; with 0 parameter(s) on connection ecpg1_regression
102+
[NO_PID]: sqlca: code: 0, state: 00000
103+
[NO_PID]: ecpg_execute on line 57: using PQexec
104+
[NO_PID]: sqlca: code: 0, state: 00000
105+
[NO_PID]: ecpg_process_output on line 57: OK: CLOSE CURSOR
106+
[NO_PID]: sqlca: code: 0, state: 00000
107+
[NO_PID]: ecpg_execute on line 60: query: drop table emp; with 0 parameter(s) on connection ecpg1_regression
108+
[NO_PID]: sqlca: code: 0, state: 00000
109+
[NO_PID]: ecpg_execute on line 60: using PQexec
110+
[NO_PID]: sqlca: code: 0, state: 00000
111+
[NO_PID]: ecpg_process_output on line 60: OK: DROP TABLE
112+
[NO_PID]: sqlca: code: 0, state: 00000
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
josh 10000.00 10.00
2+
Ram 111100.00 21.00

‎src/interfaces/ecpg/test/preproc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ TESTS = array_of_struct array_of_struct.c \
1515
type type.c\
1616
variable variable.c\
1717
whenever whenever.c\
18+
whenever_do_continue whenever_do_continue.c\
1819
pointer_to_struct pointer_to_struct.c
1920

2021
all:$(TESTS)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp