aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/expected/complex-test3.c
blob: e97822a8ce3115020322bc35e92d035703660405 (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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* Processed by ecpg (4.2.1) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */

#line 1 "test3.pgc"
/****************************************************************************/
/* Test comment                                                             */
/*--------------------------------------------------------------------------*/

#line 1 "./header_test.h"
#include "stdlib.h"

static void
Finish(char *msg)
{
	fprintf(stderr, "Error in statement '%s':\n", msg);
	sqlprint();

	/* finish transaction */
	{ ECPGtrans(__LINE__, NULL, "rollback");}
#line 10 "./header_test.h"


	/* and remove test table */
	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table meskes ", ECPGt_EOIT, ECPGt_EORT);}
#line 13 "./header_test.h"

	{ ECPGtrans(__LINE__, NULL, "commit");}
#line 14 "./header_test.h"


	{ ECPGdisconnect(__LINE__, "CURRENT");}
#line 16 "./header_test.h"


	exit(-1);
}

static void
warn(void)
{
	fprintf(stderr, "Warning: At least one column was truncated\n");
}

/* exec sql whenever sqlerror  do Finish ( msg ) ; */
#line 29 "./header_test.h"

/* exec sql whenever sql_warning  do warn (  ) ; */
#line 32 "./header_test.h"


#line 4 "test3.pgc"


#line 1 "./../regression.h"






#line 5 "test3.pgc"


/* exec sql type str is  [ 10 ]   */
#line 7 "test3.pgc"


#include <stdlib.h>
#include <string.h>

int
main (void)
{
/* exec sql begin declare section */
	        typedef struct { 
#line 16 "test3.pgc"
 long  born    ;
 
#line 16 "test3.pgc"
 short  age    ;
 }  birthinfo ;

#line 16 "test3.pgc"

	 		 
					 
				 
	  	 
					 
				   
	   
	    
	 
	   
	 
	 
 
#line 19 "test3.pgc"
 struct personal_struct { 
#line 17 "test3.pgc"
   struct varchar_name  { int len; char arr[ 10 ]; }  name    ;
 
#line 18 "test3.pgc"
 birthinfo  birth    ;
 }  personal    ;
 
#line 22 "test3.pgc"
 struct personal_indicator { 
#line 20 "test3.pgc"
 int  ind_name    ;
 
#line 21 "test3.pgc"
 birthinfo  ind_birth    ;
 }  ind_personal    ;
 
#line 23 "test3.pgc"
 int * ind_married   = NULL ;
 
#line 24 "test3.pgc"
 int  children    ,  movevalue   = 2 ;
 
#line 25 "test3.pgc"
 int  ind_children    ;
 
#line 26 "test3.pgc"
   struct varchar_married  { int len; char arr[ 10 ]; } * married  = NULL ;
 
#line 27 "test3.pgc"
 char * wifesname   = "Petra" ;
 
#line 28 "test3.pgc"
 char * query   = "select * from meskes where name = ?" ;
/* exec sql end declare section */
#line 29 "test3.pgc"


	/* declare cur  cursor  for select  name , born , age , married , children  from meskes    */
#line 32 "test3.pgc"


	char msg[128];

	ECPGdebug(1, stderr);

	strcpy(msg, "connect");
	{ ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); 
#line 39 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 39 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 39 "test3.pgc"


	strcpy(msg, "create");
	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table meskes ( name char  ( 8 )    , born integer   , age smallint   , married date   , children integer   )    ", ECPGt_EOIT, ECPGt_EORT);
#line 42 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 42 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 42 "test3.pgc"


	strcpy(msg, "insert");
	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into meskes ( name  , married  , children  ) values(  ? , '19900404' , 3 )", 
	ECPGt_char,&(wifesname),(long)0,(long)1,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 45 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 45 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 45 "test3.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into meskes ( name  , born  , age  , married  , children  ) values( 'Michael' , 19660117 , 35 , '19900404' , 3 )", ECPGt_EOIT, ECPGt_EORT);
#line 46 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 46 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 46 "test3.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into meskes ( name  , born  , age  ) values( 'Carsten' , 19910103 , 10 )", ECPGt_EOIT, ECPGt_EORT);
#line 47 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 47 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 47 "test3.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into meskes ( name  , born  , age  ) values( 'Marc' , 19930907 , 8 )", ECPGt_EOIT, ECPGt_EORT);
#line 48 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 48 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 48 "test3.pgc"

	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into meskes ( name  , born  , age  ) values( 'Chris' , 19970923 , 4 )", ECPGt_EOIT, ECPGt_EORT);
#line 49 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 49 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 49 "test3.pgc"


	strcpy(msg, "commit");
	{ ECPGtrans(__LINE__, NULL, "commit");
#line 52 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 52 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 52 "test3.pgc"


	strcpy(msg, "open");
	{ ECPGdo(__LINE__, 0, 1, NULL, "declare cur  cursor  for select  name , born , age , married , children  from meskes   ", ECPGt_EOIT, ECPGt_EORT);
#line 55 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 55 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 55 "test3.pgc"


	strcpy(msg, "move");
	{ ECPGdo(__LINE__, 0, 1, NULL, "move  ? in cur", 
	ECPGt_int,&(movevalue),(long)1,(long)1,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 58 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 58 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 58 "test3.pgc"


	/* exec sql whenever not found  break ; */
#line 60 "test3.pgc"


	while (1) {
		strcpy(msg, "fetch");
		{ ECPGdo(__LINE__, 0, 1, NULL, "fetch from cur", ECPGt_EOIT, 
	ECPGt_varchar,&(personal.name),(long)10,(long)1,sizeof(struct varchar_name), 
	ECPGt_int,&(ind_personal.ind_name),(long)1,(long)1,sizeof(int), 
	ECPGt_long,&(personal.birth.born),(long)1,(long)1,sizeof(long), 
	ECPGt_long,&(ind_personal.ind_birth.born),(long)1,(long)1,sizeof(long), 
	ECPGt_short,&(personal.birth.age),(long)1,(long)1,sizeof(short), 
	ECPGt_short,&(ind_personal.ind_birth.age),(long)1,(long)1,sizeof(short), 
	ECPGt_varchar,&(married),(long)10,(long)0,sizeof(struct varchar_married), 
	ECPGt_int,&(ind_married),(long)1,(long)0,sizeof(int), 
	ECPGt_int,&(children),(long)1,(long)1,sizeof(int), 
	ECPGt_int,&(ind_children),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 64 "test3.pgc"

if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
#line 64 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 64 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 64 "test3.pgc"

		printf("%8.8s", personal.name.arr);
		if (ind_personal.ind_birth.born >= 0)
			printf(", born %ld", personal.birth.born);
		if (ind_personal.ind_birth.age >= 0)
			printf(", age = %d", personal.birth.age);
		if (*ind_married >= 0)
			printf(", married %10.10s", married->arr);
		if (ind_children >= 0)
			printf(", children = %d", children);
		putchar('\n');

		free(married);
		married = NULL;
	}

	strcpy(msg, "close");
	{ ECPGdo(__LINE__, 0, 1, NULL, "close cur", ECPGt_EOIT, ECPGt_EORT);
#line 81 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 81 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 81 "test3.pgc"


	/* and now a query with prepare */
	{ ECPGprepare(__LINE__, "MM" , query);
#line 84 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 84 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 84 "test3.pgc"

	/* declare prep  cursor  for ? */
#line 85 "test3.pgc"


	strcpy(msg, "open");
	{ ECPGdo(__LINE__, 0, 1, NULL, "declare prep  cursor  for ?", 
	ECPGt_char_variable,(ECPGprepared_statement("MM")),(long)1,(long)1,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_char,&(wifesname),(long)0,(long)1,(1)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 88 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 88 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 88 "test3.pgc"


	/* exec sql whenever not found  break ; */
#line 90 "test3.pgc"


	while (1) {
		strcpy(msg, "fetch");
		{ ECPGdo(__LINE__, 0, 1, NULL, "fetch in prep", ECPGt_EOIT, 
	ECPGt_varchar,&(personal.name),(long)10,(long)1,sizeof(struct varchar_name), 
	ECPGt_int,&(ind_personal.ind_name),(long)1,(long)1,sizeof(int), 
	ECPGt_long,&(personal.birth.born),(long)1,(long)1,sizeof(long), 
	ECPGt_long,&(ind_personal.ind_birth.born),(long)1,(long)1,sizeof(long), 
	ECPGt_short,&(personal.birth.age),(long)1,(long)1,sizeof(short), 
	ECPGt_short,&(ind_personal.ind_birth.age),(long)1,(long)1,sizeof(short), 
	ECPGt_varchar,&(married),(long)10,(long)0,sizeof(struct varchar_married), 
	ECPGt_int,&(ind_married),(long)1,(long)0,sizeof(int), 
	ECPGt_int,&(children),(long)1,(long)1,sizeof(int), 
	ECPGt_int,&(ind_children),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 94 "test3.pgc"

if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
#line 94 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 94 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 94 "test3.pgc"

		printf("%8.8s", personal.name.arr);
		if (ind_personal.ind_birth.born >= 0)
			printf(", born %ld", personal.birth.born);
		if (ind_personal.ind_birth.age >= 0)
			printf(", age = %d", personal.birth.age);
		if (*ind_married >= 0)
			printf(", married %10.10s", married->arr);
		if (ind_children >= 0)
			printf(", children = %d", children);
		putchar('\n');
	}

	free(married);

	strcpy(msg, "close");
	{ ECPGdo(__LINE__, 0, 1, NULL, "close prep", ECPGt_EOIT, ECPGt_EORT);
#line 110 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 110 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 110 "test3.pgc"


	strcpy(msg, "drop");
	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table meskes ", ECPGt_EOIT, ECPGt_EORT);
#line 113 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 113 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 113 "test3.pgc"


	strcpy(msg, "commit");
	{ ECPGtrans(__LINE__, NULL, "commit");
#line 116 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 116 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 116 "test3.pgc"


	strcpy(msg, "disconnect"); 
	{ ECPGdisconnect(__LINE__, "CURRENT");
#line 119 "test3.pgc"

if (sqlca.sqlwarn[0] == 'W') warn (  );
#line 119 "test3.pgc"

if (sqlca.sqlcode < 0) Finish ( msg );}
#line 119 "test3.pgc"


	return (0);
}