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 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8
9 #line 1 "execute.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14
15
16 #line 1 "regression.h"
17
18
19
20
21
22
23 #line 6 "execute.pgc"
24
25
26 /* exec sql whenever sqlerror sqlprint ; */
27 #line 8 "execute.pgc"
28
29
30 int
main(void)31 main(void)
32 {
33 /* exec sql begin declare section */
34
35
36
37
38
39
40 #line 14 "execute.pgc"
41 int amount [ 8 ] ;
42
43 #line 15 "execute.pgc"
44 int increment = 100 ;
45
46 #line 16 "execute.pgc"
47 char name [ 8 ] [ 8 ] ;
48
49 #line 17 "execute.pgc"
50 char letter [ 8 ] [ 1 ] ;
51
52 #line 18 "execute.pgc"
53 char command [ 128 ] ;
54 /* exec sql end declare section */
55 #line 19 "execute.pgc"
56
57 int i,j;
58
59 ECPGdebug(1, stderr);
60
61 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "main", 0);
62 #line 24 "execute.pgc"
63
64 if (sqlca.sqlcode < 0) sqlprint();}
65 #line 24 "execute.pgc"
66
67 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
68 #line 25 "execute.pgc"
69
70 if (sqlca.sqlcode < 0) sqlprint();}
71 #line 25 "execute.pgc"
72
73 { ECPGtrans(__LINE__, NULL, "commit");
74 #line 26 "execute.pgc"
75
76 if (sqlca.sqlcode < 0) sqlprint();}
77 #line 26 "execute.pgc"
78
79
80 sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
81 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
82 #line 29 "execute.pgc"
83
84 if (sqlca.sqlcode < 0) sqlprint();}
85 #line 29 "execute.pgc"
86
87
88 sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
89 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
90 #line 32 "execute.pgc"
91
92 if (sqlca.sqlcode < 0) sqlprint();}
93 #line 32 "execute.pgc"
94
95
96 sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
97 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
98 #line 35 "execute.pgc"
99
100 if (sqlca.sqlcode < 0) sqlprint();}
101 #line 35 "execute.pgc"
102
103
104 printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
105
106 sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
107 { ECPGprepare(__LINE__, NULL, 0, "i", command);
108 #line 40 "execute.pgc"
109
110 if (sqlca.sqlcode < 0) sqlprint();}
111 #line 40 "execute.pgc"
112
113 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
114 ECPGt_int,&(increment),(long)1,(long)1,sizeof(int),
115 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
116 #line 41 "execute.pgc"
117
118 if (sqlca.sqlcode < 0) sqlprint();}
119 #line 41 "execute.pgc"
120
121
122 printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
123
124 { ECPGtrans(__LINE__, NULL, "commit");
125 #line 45 "execute.pgc"
126
127 if (sqlca.sqlcode < 0) sqlprint();}
128 #line 45 "execute.pgc"
129
130
131 sprintf (command, "select * from test");
132
133 { ECPGprepare(__LINE__, NULL, 0, "f", command);
134 #line 49 "execute.pgc"
135
136 if (sqlca.sqlcode < 0) sqlprint();}
137 #line 49 "execute.pgc"
138
139 /* declare CUR cursor for $1 */
140 #line 50 "execute.pgc"
141
142
143 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR cursor for $1",
144 ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
145 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
146 #line 52 "execute.pgc"
147
148 if (sqlca.sqlcode < 0) sqlprint();}
149 #line 52 "execute.pgc"
150
151 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT,
152 ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
153 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
154 ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
155 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
156 ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
157 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
158 #line 53 "execute.pgc"
159
160 if (sqlca.sqlcode < 0) sqlprint();}
161 #line 53 "execute.pgc"
162
163
164 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
165 {
166 /* exec sql begin declare section */
167
168
169
170 #line 58 "execute.pgc"
171 char n [ 8 ] , l = letter [ i ] [ 0 ] ;
172
173 #line 59 "execute.pgc"
174 int a = amount [ i ] ;
175 /* exec sql end declare section */
176 #line 60 "execute.pgc"
177
178
179 strncpy(n, name[i], 8);
180 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
181 }
182
183 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
184 #line 66 "execute.pgc"
185
186 if (sqlca.sqlcode < 0) sqlprint();}
187 #line 66 "execute.pgc"
188
189 { ECPGdeallocate(__LINE__, 0, NULL, "f");
190 #line 67 "execute.pgc"
191
192 if (sqlca.sqlcode < 0) sqlprint();}
193 #line 67 "execute.pgc"
194
195
196 sprintf (command, "select * from test where amount = $1");
197
198 { ECPGprepare(__LINE__, NULL, 0, "f", command);
199 #line 71 "execute.pgc"
200
201 if (sqlca.sqlcode < 0) sqlprint();}
202 #line 71 "execute.pgc"
203
204 /* declare CUR2 cursor for $1 */
205 #line 72 "execute.pgc"
206
207
208 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR2 cursor for $1",
209 ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
210 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
211 ECPGt_const,"1",(long)1,(long)1,strlen("1"),
212 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
213 #line 74 "execute.pgc"
214
215 if (sqlca.sqlcode < 0) sqlprint();}
216 #line 74 "execute.pgc"
217
218 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in CUR2", ECPGt_EOIT,
219 ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
220 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
221 ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
222 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
223 ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
224 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
225 #line 75 "execute.pgc"
226
227 if (sqlca.sqlcode < 0) sqlprint();}
228 #line 75 "execute.pgc"
229
230
231 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
232 {
233 /* exec sql begin declare section */
234
235
236
237 #line 80 "execute.pgc"
238 char n [ 8 ] , l = letter [ i ] [ 0 ] ;
239
240 #line 81 "execute.pgc"
241 int a = amount [ i ] ;
242 /* exec sql end declare section */
243 #line 82 "execute.pgc"
244
245
246 strncpy(n, name[i], 8);
247 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
248 }
249
250 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
251 #line 88 "execute.pgc"
252
253 if (sqlca.sqlcode < 0) sqlprint();}
254 #line 88 "execute.pgc"
255
256 { ECPGdeallocate(__LINE__, 0, NULL, "f");
257 #line 89 "execute.pgc"
258
259 if (sqlca.sqlcode < 0) sqlprint();}
260 #line 89 "execute.pgc"
261
262
263 sprintf (command, "select * from test where amount = $1");
264
265 { ECPGprepare(__LINE__, NULL, 0, "f", command);
266 #line 93 "execute.pgc"
267
268 if (sqlca.sqlcode < 0) sqlprint();}
269 #line 93 "execute.pgc"
270
271 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "f",
272 ECPGt_const,"2",(long)1,(long)1,strlen("2"),
273 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
274 ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
275 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
276 ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
277 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
278 ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
279 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
280 #line 94 "execute.pgc"
281
282 if (sqlca.sqlcode < 0) sqlprint();}
283 #line 94 "execute.pgc"
284
285
286 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
287 {
288 /* exec sql begin declare section */
289
290
291
292 #line 99 "execute.pgc"
293 char n [ 8 ] , l = letter [ i ] [ 0 ] ;
294
295 #line 100 "execute.pgc"
296 int a = amount [ i ] ;
297 /* exec sql end declare section */
298 #line 101 "execute.pgc"
299
300
301 strncpy(n, name[i], 8);
302 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
303 }
304
305 { ECPGdeallocate(__LINE__, 0, NULL, "f");
306 #line 107 "execute.pgc"
307
308 if (sqlca.sqlcode < 0) sqlprint();}
309 #line 107 "execute.pgc"
310
311 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
312 #line 108 "execute.pgc"
313
314 if (sqlca.sqlcode < 0) sqlprint();}
315 #line 108 "execute.pgc"
316
317 { ECPGtrans(__LINE__, NULL, "commit");
318 #line 109 "execute.pgc"
319
320 if (sqlca.sqlcode < 0) sqlprint();}
321 #line 109 "execute.pgc"
322
323 { ECPGdisconnect(__LINE__, "CURRENT");
324 #line 110 "execute.pgc"
325
326 if (sqlca.sqlcode < 0) sqlprint();}
327 #line 110 "execute.pgc"
328
329
330 return 0;
331 }
332