26
26
int main () {
27
27
/* exec sql begin declare section */
28
28
29
+
30
+
29
31
30
32
#line 10 "autoprep.pgc"
31
33
int item [ 4 ] , ind [ 4 ] , i = 1 ;
32
- /* exec sql end declare section */
34
+
33
35
#line 11 "autoprep.pgc"
36
+ int item1 , ind1 ;
37
+
38
+ #line 12 "autoprep.pgc"
39
+ char sqlstr [ 64 ] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST" ;
40
+ /* exec sql end declare section */
41
+ #line 13 "autoprep.pgc"
34
42
35
43
36
44
ECPGdebug (1 , stderr );
37
45
{ ECPGconnect (__LINE__ , 0 , "regress1" , NULL , NULL , NULL , 0 ); }
38
- #line 14 "autoprep.pgc"
46
+ #line 16 "autoprep.pgc"
39
47
40
48
41
49
/* exec sql whenever sql_warning sqlprint ; */
42
- #line 16 "autoprep.pgc"
50
+ #line 18 "autoprep.pgc"
43
51
44
52
/* exec sql whenever sqlerror sqlprint ; */
45
- #line 17 "autoprep.pgc"
53
+ #line 19 "autoprep.pgc"
46
54
47
55
48
- { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "create table T ( Item1 int , Item2 int )" , ECPGt_EOIT , ECPGt_EORT );
49
- #line 19 "autoprep.pgc"
56
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "create table T ( Item1 int , Item2 int )" , ECPGt_EOIT , ECPGt_EORT );
57
+ #line 21 "autoprep.pgc"
50
58
51
59
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
52
- #line 19 "autoprep.pgc"
60
+ #line 21 "autoprep.pgc"
53
61
54
62
if (sqlca .sqlcode < 0 ) sqlprint ();}
55
- #line 19 "autoprep.pgc"
63
+ #line 21 "autoprep.pgc"
56
64
57
65
58
66
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "insert into T values ( 1 , null )" , ECPGt_EOIT , ECPGt_EORT );
59
- #line 21 "autoprep.pgc"
67
+ #line 23 "autoprep.pgc"
60
68
61
69
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
62
- #line 21 "autoprep.pgc"
70
+ #line 23 "autoprep.pgc"
63
71
64
72
if (sqlca .sqlcode < 0 ) sqlprint ();}
65
- #line 21 "autoprep.pgc"
73
+ #line 23 "autoprep.pgc"
66
74
67
75
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "insert into T values ( 1 , $1 )" ,
68
76
ECPGt_int ,& (i ),(long )1 ,(long )1 ,sizeof (int ),
69
77
ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EOIT , ECPGt_EORT );
70
- #line 22 "autoprep.pgc"
78
+ #line 24 "autoprep.pgc"
71
79
72
80
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
73
- #line 22 "autoprep.pgc"
81
+ #line 24 "autoprep.pgc"
74
82
75
83
if (sqlca .sqlcode < 0 ) sqlprint ();}
76
- #line 22 "autoprep.pgc"
84
+ #line 24 "autoprep.pgc"
77
85
78
86
i ++ ;
79
87
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "insert into T values ( 1 , $1 )" ,
80
88
ECPGt_int ,& (i ),(long )1 ,(long )1 ,sizeof (int ),
81
89
ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EOIT , ECPGt_EORT );
82
- #line 24 "autoprep.pgc"
90
+ #line 26 "autoprep.pgc"
83
91
84
92
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
85
- #line 24 "autoprep.pgc"
93
+ #line 26 "autoprep.pgc"
86
94
87
95
if (sqlca .sqlcode < 0 ) sqlprint ();}
88
- #line 24 "autoprep.pgc"
96
+ #line 26 "autoprep.pgc"
89
97
90
98
{ ECPGprepare (__LINE__ , NULL , 0 , "i" , " insert into T values ( 1 , 2 ) " );
91
- #line 25 "autoprep.pgc"
99
+ #line 27 "autoprep.pgc"
92
100
93
101
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
94
- #line 25 "autoprep.pgc"
102
+ #line 27 "autoprep.pgc"
95
103
96
104
if (sqlca .sqlcode < 0 ) sqlprint ();}
97
- #line 25 "autoprep.pgc"
105
+ #line 27 "autoprep.pgc"
98
106
99
- { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , 1 , "i" , ECPGt_EOIT , ECPGt_EORT );
100
- #line 26 "autoprep.pgc"
107
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_execute , "i" , ECPGt_EOIT , ECPGt_EORT );
108
+ #line 28 "autoprep.pgc"
101
109
102
110
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
103
- #line 26 "autoprep.pgc"
111
+ #line 28 "autoprep.pgc"
104
112
105
113
if (sqlca .sqlcode < 0 ) sqlprint ();}
106
- #line 26 "autoprep.pgc"
114
+ #line 28 "autoprep.pgc"
107
115
108
116
109
117
{ ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "select Item2 from T order by Item2 nulls last" , ECPGt_EOIT ,
110
118
ECPGt_int ,(item ),(long )1 ,(long )4 ,sizeof (int ),
111
119
ECPGt_int ,(ind ),(long )1 ,(long )4 ,sizeof (int ), ECPGt_EORT );
112
- #line 28 "autoprep.pgc"
120
+ #line 30 "autoprep.pgc"
113
121
114
122
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
115
- #line 28 "autoprep.pgc"
123
+ #line 30 "autoprep.pgc"
116
124
117
125
if (sqlca .sqlcode < 0 ) sqlprint ();}
118
- #line 28 "autoprep.pgc"
126
+ #line 30 "autoprep.pgc"
119
127
120
128
121
129
for (i = 0 ; i < 4 ; i ++ )
122
130
printf ("item[%d] = %d\n" , i , ind [i ] ? -1 : item [i ]);
123
131
124
132
/* declare C cursor for select Item1 from T */
125
- #line 33 "autoprep.pgc"
126
-
127
-
128
- { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "declare C cursor for select Item1 from T" , ECPGt_EOIT , ECPGt_EORT );
129
- #line 35 "autoprep.pgc"
130
-
131
- if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
132
- #line 35 "autoprep.pgc"
133
-
134
- if (sqlca .sqlcode < 0 ) sqlprint ();}
135
133
#line 35 "autoprep.pgc"
136
134
137
135
138
- { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "fetch 1 in C" , ECPGt_EOIT ,
139
- ECPGt_int ,& (i ),(long )1 ,(long )1 ,sizeof (int ),
140
- ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EORT );
136
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "declare C cursor for select Item1 from T" , ECPGt_EOIT , ECPGt_EORT );
141
137
#line 37 "autoprep.pgc"
142
138
143
139
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
@@ -146,19 +142,21 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
146
142
if (sqlca .sqlcode < 0 ) sqlprint ();}
147
143
#line 37 "autoprep.pgc"
148
144
149
- printf ("i = %d\n" , i );
150
145
151
- { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "close C" , ECPGt_EOIT , ECPGt_EORT );
152
- #line 40 "autoprep.pgc"
146
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "fetch 1 in C" , ECPGt_EOIT ,
147
+ ECPGt_int ,& (i ),(long )1 ,(long )1 ,sizeof (int ),
148
+ ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EORT );
149
+ #line 39 "autoprep.pgc"
153
150
154
151
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
155
- #line 40 "autoprep.pgc"
152
+ #line 39 "autoprep.pgc"
156
153
157
154
if (sqlca .sqlcode < 0 ) sqlprint ();}
158
- #line 40 "autoprep.pgc"
155
+ #line 39 "autoprep.pgc"
159
156
157
+ printf ("i = %d\n" , i );
160
158
161
- { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_prepnormal , "drop table T " , ECPGt_EOIT , ECPGt_EORT );
159
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "close C " , ECPGt_EOIT , ECPGt_EORT );
162
160
#line 42 "autoprep.pgc"
163
161
164
162
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
@@ -168,7 +166,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
168
166
#line 42 "autoprep.pgc"
169
167
170
168
171
- { ECPGdisconnect (__LINE__ , "ALL" );
169
+ { ECPGprepare (__LINE__ , NULL , 0 , "stmt1" , sqlstr );
172
170
#line 44 "autoprep.pgc"
173
171
174
172
if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
@@ -178,5 +176,76 @@ if (sqlca.sqlcode < 0) sqlprint();}
178
176
#line 44 "autoprep.pgc"
179
177
180
178
179
+ /* declare cur1 cursor for $1 */
180
+ #line 46 "autoprep.pgc"
181
+
182
+
183
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "declare cur1 cursor for $1" ,
184
+ ECPGt_char_variable ,(ECPGprepared_statement (NULL , "stmt1" , __LINE__ )),(long )1 ,(long )1 ,(1 )* sizeof (char ),
185
+ ECPGt_NO_INDICATOR , NULL , 0L , 0L , 0L , ECPGt_EOIT , ECPGt_EORT );
186
+ #line 48 "autoprep.pgc"
187
+
188
+ if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
189
+ #line 48 "autoprep.pgc"
190
+
191
+ if (sqlca .sqlcode < 0 ) sqlprint ();}
192
+ #line 48 "autoprep.pgc"
193
+
194
+
195
+ /* exec sql whenever not found break ; */
196
+ #line 50 "autoprep.pgc"
197
+
198
+
199
+ i = 0 ;
200
+ while (1 )
201
+ {
202
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "fetch cur1" , ECPGt_EOIT ,
203
+ ECPGt_int ,& (item1 ),(long )1 ,(long )1 ,sizeof (int ),
204
+ ECPGt_int ,& (ind1 ),(long )1 ,(long )1 ,sizeof (int ), ECPGt_EORT );
205
+ #line 55 "autoprep.pgc"
206
+
207
+ if (sqlca .sqlcode == ECPG_NOT_FOUND ) break ;
208
+ #line 55 "autoprep.pgc"
209
+
210
+ if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
211
+ #line 55 "autoprep.pgc"
212
+
213
+ if (sqlca .sqlcode < 0 ) sqlprint ();}
214
+ #line 55 "autoprep.pgc"
215
+
216
+ printf ("item[%d] = %d\n" , i , ind1 ? -1 : item1 );
217
+ i ++ ;
218
+ }
219
+
220
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "close cur1" , ECPGt_EOIT , ECPGt_EORT );
221
+ #line 60 "autoprep.pgc"
222
+
223
+ if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
224
+ #line 60 "autoprep.pgc"
225
+
226
+ if (sqlca .sqlcode < 0 ) sqlprint ();}
227
+ #line 60 "autoprep.pgc"
228
+
229
+
230
+ { ECPGdo (__LINE__ , 0 , 1 , NULL , 0 , ECPGst_normal , "drop table T" , ECPGt_EOIT , ECPGt_EORT );
231
+ #line 62 "autoprep.pgc"
232
+
233
+ if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
234
+ #line 62 "autoprep.pgc"
235
+
236
+ if (sqlca .sqlcode < 0 ) sqlprint ();}
237
+ #line 62 "autoprep.pgc"
238
+
239
+
240
+ { ECPGdisconnect (__LINE__ , "ALL" );
241
+ #line 64 "autoprep.pgc"
242
+
243
+ if (sqlca .sqlwarn [0 ] == 'W' ) sqlprint ();
244
+ #line 64 "autoprep.pgc"
245
+
246
+ if (sqlca .sqlcode < 0 ) sqlprint ();}
247
+ #line 64 "autoprep.pgc"
248
+
249
+
181
250
return 0 ;
182
251
}
0 commit comments