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 /* Needed for informix compatibility */
7 #include <ecpg_informix.h>
8 /* End of automatic include section */
9 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
10
11 #line 1 "sqlda.pgc"
12 #include <stdlib.h>
13 #include <string.h>
14 #include <limits.h>
15
16
17 #line 1 "regression.h"
18
19
20
21
22
23
24 #line 5 "sqlda.pgc"
25
26
27
28 #line 1 "sqlda.h"
29 #ifndef ECPG_SQLDA_H
30 #define ECPG_SQLDA_H
31
32 #ifdef _ECPG_INFORMIX_H
33
34 #include "sqlda-compat.h"
35 typedef struct sqlvar_compat sqlvar_t;
36 typedef struct sqlda_compat sqlda_t;
37
38 #else
39
40 #include "sqlda-native.h"
41 typedef struct sqlvar_struct sqlvar_t;
42 typedef struct sqlda_struct sqlda_t;
43
44 #endif
45
46 #endif /* ECPG_SQLDA_H */
47
48 #line 7 "sqlda.pgc"
49
50
51 #line 1 "sqltypes.h"
52 #ifndef ECPG_SQLTYPES_H
53 #define ECPG_SQLTYPES_H
54
55 #include <limits.h>
56
57 #define CCHARTYPE ECPGt_char
58 #define CSHORTTYPE ECPGt_short
59 #define CINTTYPE ECPGt_int
60 #define CLONGTYPE ECPGt_long
61 #define CFLOATTYPE ECPGt_float
62 #define CDOUBLETYPE ECPGt_double
63 #define CDECIMALTYPE ECPGt_decimal
64 #define CFIXCHARTYPE 108
65 #define CSTRINGTYPE ECPGt_char
66 #define CDATETYPE ECPGt_date
67 #define CMONEYTYPE 111
68 #define CDTIMETYPE ECPGt_timestamp
69 #define CLOCATORTYPE 113
70 #define CVCHARTYPE ECPGt_varchar
71 #define CINVTYPE 115
72 #define CFILETYPE 116
73 #define CINT8TYPE ECPGt_long_long
74 #define CCOLLTYPE 118
75 #define CLVCHARTYPE 119
76 #define CFIXBINTYPE 120
77 #define CVARBINTYPE 121
78 #define CBOOLTYPE ECPGt_bool
79 #define CROWTYPE 123
80 #define CLVCHARPTRTYPE 124
81 #define CTYPEMAX 25
82
83 /*
84 * Values used in sqlda->sqlvar[i]->sqltype
85 */
86 #define SQLCHAR ECPGt_char
87 #define SQLSMINT ECPGt_short
88 #define SQLINT ECPGt_int
89 #define SQLFLOAT ECPGt_double
90 #define SQLSMFLOAT ECPGt_float
91 #define SQLDECIMAL ECPGt_decimal
92 #define SQLSERIAL ECPGt_int
93 #define SQLDATE ECPGt_date
94 #define SQLDTIME ECPGt_timestamp
95 #define SQLTEXT ECPGt_char
96 #define SQLVCHAR ECPGt_char
97 #define SQLINTERVAL ECPGt_interval
98 #define SQLNCHAR ECPGt_char
99 #define SQLNVCHAR ECPGt_char
100 #ifdef HAVE_LONG_LONG_INT_64
101 #define SQLINT8 ECPGt_long_long
102 #define SQLSERIAL8 ECPGt_long_long
103 #else
104 #define SQLINT8 ECPGt_long
105 #define SQLSERIAL8 ECPGt_long
106 #endif
107
108 #endif /* ndef ECPG_SQLTYPES_H */
109
110 #line 8 "sqlda.pgc"
111
112
113 /* exec sql whenever sqlerror stop ; */
114 #line 10 "sqlda.pgc"
115
116
117 /* These shouldn't be under DECLARE SECTION */
118 sqlda_t *inp_sqlda, *outp_sqlda;
119
120 static void
dump_sqlda(sqlda_t * sqlda)121 dump_sqlda(sqlda_t *sqlda)
122 {
123 int i;
124
125 if (sqlda == NULL)
126 {
127 printf("dump_sqlda called with NULL sqlda\n");
128 return;
129 }
130
131 for (i = 0; i < sqlda->sqld; i++)
132 {
133 if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
134 printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname);
135 else
136 switch (sqlda->sqlvar[i].sqltype)
137 {
138 case SQLCHAR:
139 printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname, sqlda->sqlvar[i].sqldata);
140 break;
141 case SQLINT:
142 printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname, *(int *)sqlda->sqlvar[i].sqldata);
143 break;
144 case SQLFLOAT:
145 printf("name sqlda descriptor: '%s' value %f\n", sqlda->sqlvar[i].sqlname, *(double *)sqlda->sqlvar[i].sqldata);
146 break;
147 case SQLDECIMAL:
148 {
149 char val[64];
150 dectoasc((decimal *)sqlda->sqlvar[i].sqldata, val, 64, -1);
151 printf("name sqlda descriptor: '%s' value DECIMAL '%s'\n", sqlda->sqlvar[i].sqlname, val);
152 break;
153 }
154 }
155 }
156 }
157
158 int
main(void)159 main (void)
160 {
161 /* exec sql begin declare section */
162
163
164
165
166
167 #line 57 "sqlda.pgc"
168 char * stmt1 = "SELECT * FROM t1" ;
169
170 #line 58 "sqlda.pgc"
171 char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
172
173 #line 59 "sqlda.pgc"
174 int rec ;
175
176 #line 60 "sqlda.pgc"
177 int id ;
178 /* exec sql end declare section */
179 #line 61 "sqlda.pgc"
180
181
182 char msg[128];
183
184 ECPGdebug(1, stderr);
185
186 strcpy(msg, "connect");
187 { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , "regress1", 0);
188 #line 68 "sqlda.pgc"
189
190 if (sqlca.sqlcode < 0) exit (1);}
191 #line 68 "sqlda.pgc"
192
193
194 strcpy(msg, "set");
195 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
196 #line 71 "sqlda.pgc"
197
198 if (sqlca.sqlcode < 0) exit (1);}
199 #line 71 "sqlda.pgc"
200
201
202 strcpy(msg, "create");
203 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
204 #line 79 "sqlda.pgc"
205
206 if (sqlca.sqlcode < 0) exit (1);}
207 #line 79 "sqlda.pgc"
208
209
210 strcpy(msg, "insert");
211 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' ) , ( 2 , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' )", ECPGt_EOIT, ECPGt_EORT);
212 #line 85 "sqlda.pgc"
213
214 if (sqlca.sqlcode < 0) exit (1);}
215 #line 85 "sqlda.pgc"
216
217
218 strcpy(msg, "commit");
219 { ECPGtrans(__LINE__, NULL, "commit");
220 #line 88 "sqlda.pgc"
221
222 if (sqlca.sqlcode < 0) exit (1);}
223 #line 88 "sqlda.pgc"
224
225
226 /* SQLDA test for getting all records from a table */
227
228 outp_sqlda = NULL;
229
230 strcpy(msg, "prepare");
231 { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
232 #line 95 "sqlda.pgc"
233
234 if (sqlca.sqlcode < 0) exit (1);}
235 #line 95 "sqlda.pgc"
236
237
238 strcpy(msg, "declare");
239 /* declare mycur1 cursor for $1 */
240 #line 98 "sqlda.pgc"
241
242
243 strcpy(msg, "open");
244 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
245 ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
246 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
247 #line 101 "sqlda.pgc"
248
249 if (sqlca.sqlcode < 0) exit (1);}
250 #line 101 "sqlda.pgc"
251
252
253 /* exec sql whenever not found break ; */
254 #line 103 "sqlda.pgc"
255
256
257 rec = 0;
258 while (1)
259 {
260 strcpy(msg, "fetch");
261 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
262 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
263 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
264 #line 109 "sqlda.pgc"
265
266 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
267 #line 109 "sqlda.pgc"
268
269 if (sqlca.sqlcode < 0) exit (1);}
270 #line 109 "sqlda.pgc"
271
272
273 printf("FETCH RECORD %d\n", ++rec);
274 dump_sqlda(outp_sqlda);
275 }
276
277 /* exec sql whenever not found continue ; */
278 #line 115 "sqlda.pgc"
279
280
281 strcpy(msg, "close");
282 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
283 #line 118 "sqlda.pgc"
284
285 if (sqlca.sqlcode < 0) exit (1);}
286 #line 118 "sqlda.pgc"
287
288
289 strcpy(msg, "deallocate");
290 { ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
291 #line 121 "sqlda.pgc"
292
293 if (sqlca.sqlcode < 0) exit (1);}
294 #line 121 "sqlda.pgc"
295
296
297 free(outp_sqlda);
298
299 /* SQLDA test for getting all records from a table
300 using the Informix-specific FETCH ... USING DESCRIPTOR
301 */
302
303 outp_sqlda = NULL;
304
305 strcpy(msg, "prepare");
306 { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
307 #line 132 "sqlda.pgc"
308
309 if (sqlca.sqlcode < 0) exit (1);}
310 #line 132 "sqlda.pgc"
311
312
313 strcpy(msg, "declare");
314 /* declare mycur2 cursor for $1 */
315 #line 135 "sqlda.pgc"
316
317
318 strcpy(msg, "open");
319 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
320 ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
321 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
322 #line 138 "sqlda.pgc"
323
324 if (sqlca.sqlcode < 0) exit (1);}
325 #line 138 "sqlda.pgc"
326
327
328 /* exec sql whenever not found break ; */
329 #line 140 "sqlda.pgc"
330
331
332 rec = 0;
333 while (1)
334 {
335 strcpy(msg, "fetch");
336 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch from mycur2", ECPGt_EOIT,
337 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
338 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
339 #line 146 "sqlda.pgc"
340
341 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
342 #line 146 "sqlda.pgc"
343
344 if (sqlca.sqlcode < 0) exit (1);}
345 #line 146 "sqlda.pgc"
346
347
348 printf("FETCH RECORD %d\n", ++rec);
349 dump_sqlda(outp_sqlda);
350 }
351
352 /* exec sql whenever not found continue ; */
353 #line 152 "sqlda.pgc"
354
355
356 strcpy(msg, "close");
357 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
358 #line 155 "sqlda.pgc"
359
360 if (sqlca.sqlcode < 0) exit (1);}
361 #line 155 "sqlda.pgc"
362
363
364 strcpy(msg, "deallocate");
365 { ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
366 #line 158 "sqlda.pgc"
367
368 if (sqlca.sqlcode < 0) exit (1);}
369 #line 158 "sqlda.pgc"
370
371
372 free(outp_sqlda);
373
374 /* SQLDA test for getting one record using an input descriptor */
375
376 /* Input sqlda has to be built manually */
377 inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
378 memset(inp_sqlda, 0, sizeof(sqlda_t));
379 inp_sqlda->sqld = 1;
380 inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
381 memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
382
383 inp_sqlda->sqlvar[0].sqltype = SQLINT;
384 inp_sqlda->sqlvar[0].sqldata = (char *)&id;
385
386 printf("EXECUTE RECORD 4\n");
387
388 id = 4;
389
390 outp_sqlda = NULL;
391
392 strcpy(msg, "prepare");
393 { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
394 #line 181 "sqlda.pgc"
395
396 if (sqlca.sqlcode < 0) exit (1);}
397 #line 181 "sqlda.pgc"
398
399
400 strcpy(msg, "execute");
401 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_execute, "st_id3",
402 ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
403 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
404 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
405 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
406 #line 184 "sqlda.pgc"
407
408 if (sqlca.sqlcode < 0) exit (1);}
409 #line 184 "sqlda.pgc"
410
411
412 dump_sqlda(outp_sqlda);
413
414 strcpy(msg, "deallocate");
415 { ECPGdeallocate(__LINE__, 1, NULL, "st_id3");
416 #line 189 "sqlda.pgc"
417
418 if (sqlca.sqlcode < 0) exit (1);}
419 #line 189 "sqlda.pgc"
420
421
422 free(inp_sqlda->sqlvar);
423 free(inp_sqlda);
424 free(outp_sqlda);
425
426 /* SQLDA test for getting one record using an input descriptor
427 * on a named connection
428 */
429
430 { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , "con2", 0);
431 #line 199 "sqlda.pgc"
432
433 if (sqlca.sqlcode < 0) exit (1);}
434 #line 199 "sqlda.pgc"
435
436
437 /* Input sqlda has to be built manually */
438 inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
439 memset(inp_sqlda, 0, sizeof(sqlda_t));
440 inp_sqlda->sqld = 1;
441 inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
442 memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
443
444 inp_sqlda->sqlvar[0].sqltype = SQLINT;
445 inp_sqlda->sqlvar[0].sqldata = (char *)&id;
446
447 printf("EXECUTE RECORD 4\n");
448
449 id = 4;
450
451 outp_sqlda = NULL;
452
453 strcpy(msg, "prepare");
454 { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
455 #line 218 "sqlda.pgc"
456
457 if (sqlca.sqlcode < 0) exit (1);}
458 #line 218 "sqlda.pgc"
459
460
461 strcpy(msg, "execute");
462 { ECPGdo(__LINE__, 1, 1, "con2", 0, ECPGst_execute, "st_id4",
463 ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
464 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
465 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
466 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
467 #line 221 "sqlda.pgc"
468
469 if (sqlca.sqlcode < 0) exit (1);}
470 #line 221 "sqlda.pgc"
471
472
473 dump_sqlda(outp_sqlda);
474
475 strcpy(msg, "commit");
476 { ECPGtrans(__LINE__, "con2", "commit");
477 #line 226 "sqlda.pgc"
478
479 if (sqlca.sqlcode < 0) exit (1);}
480 #line 226 "sqlda.pgc"
481
482
483 strcpy(msg, "deallocate");
484 { ECPGdeallocate(__LINE__, 1, NULL, "st_id4");
485 #line 229 "sqlda.pgc"
486
487 if (sqlca.sqlcode < 0) exit (1);}
488 #line 229 "sqlda.pgc"
489
490
491 free(inp_sqlda->sqlvar);
492 free(inp_sqlda);
493 free(outp_sqlda);
494
495 strcpy(msg, "disconnect");
496 { ECPGdisconnect(__LINE__, "con2");
497 #line 236 "sqlda.pgc"
498
499 if (sqlca.sqlcode < 0) exit (1);}
500 #line 236 "sqlda.pgc"
501
502
503 /* End test */
504
505 strcpy(msg, "drop");
506 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
507 #line 241 "sqlda.pgc"
508
509 if (sqlca.sqlcode < 0) exit (1);}
510 #line 241 "sqlda.pgc"
511
512
513 strcpy(msg, "commit");
514 { ECPGtrans(__LINE__, NULL, "commit");
515 #line 244 "sqlda.pgc"
516
517 if (sqlca.sqlcode < 0) exit (1);}
518 #line 244 "sqlda.pgc"
519
520
521 strcpy(msg, "disconnect");
522 { ECPGdisconnect(__LINE__, "CURRENT");
523 #line 247 "sqlda.pgc"
524
525 if (sqlca.sqlcode < 0) exit (1);}
526 #line 247 "sqlda.pgc"
527
528
529 return 0;
530 }
531