PostgreSQL Source Code git master
compat_informix-sqlda.c
Go to the documentation of this file.
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"
35typedef struct sqlvar_compat sqlvar_t;
36typedef struct sqlda_compat sqlda_t;
37
38#else
39
40#include "sqlda-native.h"
41typedef struct sqlvar_struct sqlvar_t;
42typedef 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#if SIZEOF_LONG == 8
101#define SQLINT8 ECPGt_long
102#define SQLSERIAL8 ECPGt_long
103#elif SIZEOF_LONG_LONG == 8
104#define SQLINT8 ECPGt_long_long
105#define SQLSERIAL8 ECPGt_long_long
106#else
107#error "cannot find integer type of the same size as SQLINT8"
108#endif
109
110#endif /* ndef ECPG_SQLTYPES_H */
111
112#line 8 "sqlda.pgc"
113
114
115/* exec sql whenever sqlerror stop ; */
116#line 10 "sqlda.pgc"
117
118
119/* These shouldn't be under DECLARE SECTION */
121
122static void
124{
125 int i;
126
127 if (sqlda == NULL)
128 {
129 printf("dump_sqlda called with NULL sqlda\n");
130 return;
131 }
132
133 for (i = 0; i < sqlda->sqld; i++)
134 {
135 if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
136 printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname);
137 else
138 switch (sqlda->sqlvar[i].sqltype)
139 {
140 case SQLCHAR:
141 printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname, sqlda->sqlvar[i].sqldata);
142 break;
143 case SQLINT:
144 printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname, *(int *)sqlda->sqlvar[i].sqldata);
145 break;
146 case SQLFLOAT:
147 printf("name sqlda descriptor: '%s' value %f\n", sqlda->sqlvar[i].sqlname, *(double *)sqlda->sqlvar[i].sqldata);
148 break;
149 case SQLDECIMAL:
150 {
151 char val[64];
152 dectoasc((decimal *)sqlda->sqlvar[i].sqldata, val, 64, -1);
153 printf("name sqlda descriptor: '%s' value DECIMAL '%s'\n", sqlda->sqlvar[i].sqlname, val);
154 break;
155 }
156 }
157 }
158}
159
160int
161main (void)
162{
163/* exec sql begin declare section */
164
165
166
167
168
169#line 57 "sqlda.pgc"
170 char * stmt1 = "SELECT * FROM t1" ;
171
172#line 58 "sqlda.pgc"
173 char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
174
175#line 59 "sqlda.pgc"
176 int rec ;
177
178#line 60 "sqlda.pgc"
179 int id ;
180/* exec sql end declare section */
181#line 61 "sqlda.pgc"
182
183
184 char msg[128];
185
186 ECPGdebug(1, stderr);
187
188 strcpy(msg, "connect");
189 { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , "regress1", 0);
190#line 68 "sqlda.pgc"
191
192if (sqlca.sqlcode < 0) exit (1);}
193#line 68 "sqlda.pgc"
194
195
196 strcpy(msg, "set");
197 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
198#line 71 "sqlda.pgc"
199
200if (sqlca.sqlcode < 0) exit (1);}
201#line 71 "sqlda.pgc"
202
203
204 strcpy(msg, "create");
205 { 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);
206#line 79 "sqlda.pgc"
207
208if (sqlca.sqlcode < 0) exit (1);}
209#line 79 "sqlda.pgc"
210
211
212 strcpy(msg, "insert");
213 { 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);
214#line 85 "sqlda.pgc"
215
216if (sqlca.sqlcode < 0) exit (1);}
217#line 85 "sqlda.pgc"
218
219
220 strcpy(msg, "commit");
221 { ECPGtrans(__LINE__, NULL, "commit");
222#line 88 "sqlda.pgc"
223
224if (sqlca.sqlcode < 0) exit (1);}
225#line 88 "sqlda.pgc"
226
227
228 /* SQLDA test for getting all records from a table */
229
230 outp_sqlda = NULL;
231
232 strcpy(msg, "prepare");
233 { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
234#line 95 "sqlda.pgc"
235
236if (sqlca.sqlcode < 0) exit (1);}
237#line 95 "sqlda.pgc"
238
239
240 strcpy(msg, "declare");
241 /* declare mycur1 cursor for $1 */
242#line 98 "sqlda.pgc"
243
244
245 strcpy(msg, "open");
246 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
247 ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
248 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
249#line 101 "sqlda.pgc"
250
251if (sqlca.sqlcode < 0) exit (1);}
252#line 101 "sqlda.pgc"
253
254
255 /* exec sql whenever not found break ; */
256#line 103 "sqlda.pgc"
257
258
259 rec = 0;
260 while (1)
261 {
262 strcpy(msg, "fetch");
263 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
264 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
265 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
266#line 109 "sqlda.pgc"
267
268if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
269#line 109 "sqlda.pgc"
270
271if (sqlca.sqlcode < 0) exit (1);}
272#line 109 "sqlda.pgc"
273
274
275 printf("FETCH RECORD %d\n", ++rec);
277 }
278
279 /* exec sql whenever not found continue ; */
280#line 115 "sqlda.pgc"
281
282
283 strcpy(msg, "close");
284 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
285#line 118 "sqlda.pgc"
286
287if (sqlca.sqlcode < 0) exit (1);}
288#line 118 "sqlda.pgc"
289
290
291 strcpy(msg, "deallocate");
292 { ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
293#line 121 "sqlda.pgc"
294
295if (sqlca.sqlcode < 0) exit (1);}
296#line 121 "sqlda.pgc"
297
298
300
301 /* SQLDA test for getting all records from a table
302 using the Informix-specific FETCH ... USING DESCRIPTOR
303 */
304
305 outp_sqlda = NULL;
306
307 strcpy(msg, "prepare");
308 { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
309#line 132 "sqlda.pgc"
310
311if (sqlca.sqlcode < 0) exit (1);}
312#line 132 "sqlda.pgc"
313
314
315 strcpy(msg, "declare");
316 /* declare mycur2 cursor for $1 */
317#line 135 "sqlda.pgc"
318
319
320 strcpy(msg, "open");
321 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
322 ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
323 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
324#line 138 "sqlda.pgc"
325
326if (sqlca.sqlcode < 0) exit (1);}
327#line 138 "sqlda.pgc"
328
329
330 /* exec sql whenever not found break ; */
331#line 140 "sqlda.pgc"
332
333
334 rec = 0;
335 while (1)
336 {
337 strcpy(msg, "fetch");
338 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch from mycur2", ECPGt_EOIT,
339 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
340 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
341#line 146 "sqlda.pgc"
342
343if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
344#line 146 "sqlda.pgc"
345
346if (sqlca.sqlcode < 0) exit (1);}
347#line 146 "sqlda.pgc"
348
349
350 printf("FETCH RECORD %d\n", ++rec);
352 }
353
354 /* exec sql whenever not found continue ; */
355#line 152 "sqlda.pgc"
356
357
358 strcpy(msg, "close");
359 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
360#line 155 "sqlda.pgc"
361
362if (sqlca.sqlcode < 0) exit (1);}
363#line 155 "sqlda.pgc"
364
365
366 strcpy(msg, "deallocate");
367 { ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
368#line 158 "sqlda.pgc"
369
370if (sqlca.sqlcode < 0) exit (1);}
371#line 158 "sqlda.pgc"
372
373
375
376 /* SQLDA test for getting one record using an input descriptor */
377
378 /* Input sqlda has to be built manually */
379 inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
380 memset(inp_sqlda, 0, sizeof(sqlda_t));
381 inp_sqlda->sqld = 1;
382 inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
383 memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
384
386 inp_sqlda->sqlvar[0].sqldata = (char *)&id;
387
388 printf("EXECUTE RECORD 4\n");
389
390 id = 4;
391
392 outp_sqlda = NULL;
393
394 strcpy(msg, "prepare");
395 { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
396#line 181 "sqlda.pgc"
397
398if (sqlca.sqlcode < 0) exit (1);}
399#line 181 "sqlda.pgc"
400
401
402 strcpy(msg, "execute");
403 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_execute, "st_id3",
404 ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
405 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
406 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
407 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
408#line 184 "sqlda.pgc"
409
410if (sqlca.sqlcode < 0) exit (1);}
411#line 184 "sqlda.pgc"
412
413
415
416 strcpy(msg, "deallocate");
417 { ECPGdeallocate(__LINE__, 1, NULL, "st_id3");
418#line 189 "sqlda.pgc"
419
420if (sqlca.sqlcode < 0) exit (1);}
421#line 189 "sqlda.pgc"
422
423
427
428 /* SQLDA test for getting one record using an input descriptor
429 * on a named connection
430 */
431
432 { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , "con2", 0);
433#line 199 "sqlda.pgc"
434
435if (sqlca.sqlcode < 0) exit (1);}
436#line 199 "sqlda.pgc"
437
438
439 /* Input sqlda has to be built manually */
440 inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
441 memset(inp_sqlda, 0, sizeof(sqlda_t));
442 inp_sqlda->sqld = 1;
443 inp_sqlda->sqlvar = malloc(sizeof(sqlvar_t));
444 memset(inp_sqlda->sqlvar, 0, sizeof(sqlvar_t));
445
447 inp_sqlda->sqlvar[0].sqldata = (char *)&id;
448
449 printf("EXECUTE RECORD 4\n");
450
451 id = 4;
452
453 outp_sqlda = NULL;
454
455 strcpy(msg, "prepare");
456 { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
457#line 218 "sqlda.pgc"
458
459if (sqlca.sqlcode < 0) exit (1);}
460#line 218 "sqlda.pgc"
461
462
463 strcpy(msg, "execute");
464 { ECPGdo(__LINE__, 1, 1, "con2", 0, ECPGst_execute, "st_id4",
465 ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
466 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
467 ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
468 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
469#line 221 "sqlda.pgc"
470
471if (sqlca.sqlcode < 0) exit (1);}
472#line 221 "sqlda.pgc"
473
474
476
477 strcpy(msg, "commit");
478 { ECPGtrans(__LINE__, "con2", "commit");
479#line 226 "sqlda.pgc"
480
481if (sqlca.sqlcode < 0) exit (1);}
482#line 226 "sqlda.pgc"
483
484
485 strcpy(msg, "deallocate");
486 { ECPGdeallocate(__LINE__, 1, NULL, "st_id4");
487#line 229 "sqlda.pgc"
488
489if (sqlca.sqlcode < 0) exit (1);}
490#line 229 "sqlda.pgc"
491
492
496
497 strcpy(msg, "disconnect");
498 { ECPGdisconnect(__LINE__, "con2");
499#line 236 "sqlda.pgc"
500
501if (sqlca.sqlcode < 0) exit (1);}
502#line 236 "sqlda.pgc"
503
504
505 /* End test */
506
507 strcpy(msg, "drop");
508 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
509#line 241 "sqlda.pgc"
510
511if (sqlca.sqlcode < 0) exit (1);}
512#line 241 "sqlda.pgc"
513
514
515 strcpy(msg, "commit");
516 { ECPGtrans(__LINE__, NULL, "commit");
517#line 244 "sqlda.pgc"
518
519if (sqlca.sqlcode < 0) exit (1);}
520#line 244 "sqlda.pgc"
521
522
523 strcpy(msg, "disconnect");
524 { ECPGdisconnect(__LINE__, "CURRENT");
525#line 247 "sqlda.pgc"
526
527if (sqlca.sqlcode < 0) exit (1);}
528#line 247 "sqlda.pgc"
529
530
531 return 0;
532}
int main(void)
#define SQLCHAR
static void dump_sqlda(sqlda_t *sqlda)
#define SQLFLOAT
sqlda_t * inp_sqlda
#define SQLDECIMAL
#define ECPGdebug(X, Y)
sqlda_t * outp_sqlda
#define SQLINT
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:676
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGst_execute
Definition: ecpgtype.h:98
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_sqlda
Definition: ecpgtype.h:66
@ ECPGt_char_variable
Definition: ecpgtype.h:60
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2275
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
long val
Definition: informix.c:689
int dectoasc(decimal *np, char *cp, int len, int right)
Definition: informix.c:381
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition: prepare.c:368
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition: prepare.c:315
int i
Definition: isn.c:72
exit(1)
#define printf(...)
Definition: port.h:245
#define sqlca
Definition: sqlca.h:59
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
struct sqlname sqlname
Definition: sqlda-native.h:30
char * sqldata
Definition: sqlda-native.h:28
short * sqlind
Definition: sqlda-native.h:29