summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/expected/sql-execute.c
blob: 10e9ad56b51bf82e06b140f8234a7158cb7c3a0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/* Processed by ecpg (regression mode) */
/* These include files are added by the preprocessor */
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))

#line 1 "execute.pgc"
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>


#line 1 "regression.h"






#line 6 "execute.pgc"


/* exec sql whenever sqlerror  sqlprint ; */
#line 8 "execute.pgc"


int
main(void)
{
/* exec sql begin declare section */
	 
	 
	 
	 
	 

#line 14 "execute.pgc"
 int amount [ 8 ] ;
 
#line 15 "execute.pgc"
 int increment = 100 ;
 
#line 16 "execute.pgc"
 char name [ 8 ] [ 8 ] ;
 
#line 17 "execute.pgc"
 char letter [ 8 ] [ 1 ] ;
 
#line 18 "execute.pgc"
 char command [ 128 ] ;
/* exec sql end declare section */
#line 19 "execute.pgc"

	int i,j;

	ECPGdebug(1, stderr);

	{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "main", 0); 
#line 24 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 24 "execute.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
#line 25 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 25 "execute.pgc"

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 26 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 26 "execute.pgc"


	/* test handling of embedded quotes in EXECUTE IMMEDIATE "literal" */
	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, "insert into test (name, \042amount\042, letter) values ('db: ''r1''', 1, 'f')", ECPGt_EOIT, ECPGt_EORT);
#line 29 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 29 "execute.pgc"


	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 32 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 32 "execute.pgc"


	sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 35 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 35 "execute.pgc"


	printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);

	sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
	{ ECPGprepare(__LINE__, NULL, 0, "i", command);
#line 40 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 40 "execute.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i", 
	ECPGt_int,&(increment),(long)1,(long)1,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 41 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 41 "execute.pgc"


	printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 45 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 45 "execute.pgc"


	sprintf (command, "select * from test");

	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
#line 49 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 49 "execute.pgc"

	/* declare CUR cursor for $1 */
#line 50 "execute.pgc"


	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR cursor for $1", 
	ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 52 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 52 "execute.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, 
	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 53 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 53 "execute.pgc"


	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
	{
		/* exec sql begin declare section */
		    
		   
		
#line 58 "execute.pgc"
 char n [ 8 ] , l = letter [ i ] [ 0 ] ;
 
#line 59 "execute.pgc"
 int a = amount [ i ] ;
/* exec sql end declare section */
#line 60 "execute.pgc"


		strncpy(n, name[i], 8);
		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
	}

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
#line 66 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 66 "execute.pgc"

	{ ECPGdeallocate(__LINE__, 0, NULL, "f");
#line 67 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 67 "execute.pgc"


	sprintf (command, "select * from test where amount = $1");

	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
#line 71 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 71 "execute.pgc"

	/* declare CUR2 cursor for $1 */
#line 72 "execute.pgc"


	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR2 cursor for $1", 
	ECPGt_char_variable,(ECPGprepared_statement(NULL, "f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_const,"1",(long)1,(long)1,strlen("1"), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 74 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 74 "execute.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in CUR2", ECPGt_EOIT, 
	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 75 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 75 "execute.pgc"


	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
	{
		/* exec sql begin declare section */
		    
		   
		
#line 80 "execute.pgc"
 char n [ 8 ] , l = letter [ i ] [ 0 ] ;
 
#line 81 "execute.pgc"
 int a = amount [ i ] ;
/* exec sql end declare section */
#line 82 "execute.pgc"


		strncpy(n, name[i], 8);
		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
	}

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
#line 88 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 88 "execute.pgc"

	{ ECPGdeallocate(__LINE__, 0, NULL, "f");
#line 89 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 89 "execute.pgc"


	sprintf (command, "select * from test where amount = $1");

	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
#line 93 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 93 "execute.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "f", 
	ECPGt_const,"2",(long)1,(long)1,strlen("2"), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 94 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 94 "execute.pgc"


	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
	{
		/* exec sql begin declare section */
		    
		   
		
#line 99 "execute.pgc"
 char n [ 8 ] , l = letter [ i ] [ 0 ] ;
 
#line 100 "execute.pgc"
 int a = amount [ i ] ;
/* exec sql end declare section */
#line 101 "execute.pgc"


		strncpy(n, name[i], 8);
		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
	}

	{ ECPGdeallocate(__LINE__, 0, NULL, "f");
#line 107 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 107 "execute.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
#line 108 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 108 "execute.pgc"

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 109 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 109 "execute.pgc"

	{ ECPGdisconnect(__LINE__, "CURRENT");
#line 110 "execute.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 110 "execute.pgc"


	return 0;
}