1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
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))
11 #line 1 "describe.pgc"
16 #line 1 "regression.h"
23 #line 4 "describe.pgc"
30 #ifdef _ECPG_INFORMIX_H
32 #include "sqlda-compat.h"
33 typedef struct sqlvar_compat sqlvar_t;
34 typedef struct sqlda_compat sqlda_t;
38 #include "sqlda-native.h"
39 typedef struct sqlvar_struct sqlvar_t;
40 typedef struct sqlda_struct sqlda_t;
44 #endif /* ECPG_SQLDA_H */
46 #line 5 "describe.pgc"
49 /* exec sql whenever sqlerror stop ; */
50 #line 7 "describe.pgc"
53 sqlda_t *sqlda1, *sqlda2, *sqlda3;
58 /* exec sql begin declare section */
65 #line 15 "describe.pgc"
66 char * stmt1 = "SELECT id, t FROM descr_t1" ;
68 #line 16 "describe.pgc"
69 char * stmt2 = "SELECT id, t FROM descr_t1 WHERE id = -1" ;
71 #line 17 "describe.pgc"
72 int i , count1 , count2 ;
74 #line 18 "describe.pgc"
75 char field_name1 [ 30 ] = "not set" ;
77 #line 19 "describe.pgc"
78 char field_name2 [ 30 ] = "not set" ;
79 /* exec sql end declare section */
80 #line 20 "describe.pgc"
87 strcpy(msg, "connect");
88 { ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , NULL, 0);
89 #line 27 "describe.pgc"
91 if (sqlca.sqlcode < 0) exit (1);}
92 #line 27 "describe.pgc"
96 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
97 #line 30 "describe.pgc"
99 if (sqlca.sqlcode < 0) exit (1);}
100 #line 30 "describe.pgc"
103 strcpy(msg, "create");
104 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table descr_t1 ( id serial primary key , t text )", ECPGt_EOIT, ECPGt_EORT);
105 #line 33 "describe.pgc"
107 if (sqlca.sqlcode < 0) exit (1);}
108 #line 33 "describe.pgc"
111 strcpy(msg, "insert");
112 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'a' )", ECPGt_EOIT, ECPGt_EORT);
113 #line 36 "describe.pgc"
115 if (sqlca.sqlcode < 0) exit (1);}
116 #line 36 "describe.pgc"
118 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'b' )", ECPGt_EOIT, ECPGt_EORT);
119 #line 37 "describe.pgc"
121 if (sqlca.sqlcode < 0) exit (1);}
122 #line 37 "describe.pgc"
124 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'c' )", ECPGt_EOIT, ECPGt_EORT);
125 #line 38 "describe.pgc"
127 if (sqlca.sqlcode < 0) exit (1);}
128 #line 38 "describe.pgc"
130 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'd' )", ECPGt_EOIT, ECPGt_EORT);
131 #line 39 "describe.pgc"
133 if (sqlca.sqlcode < 0) exit (1);}
134 #line 39 "describe.pgc"
137 strcpy(msg, "commit");
138 { ECPGtrans(__LINE__, NULL, "commit");
139 #line 42 "describe.pgc"
141 if (sqlca.sqlcode < 0) exit (1);}
142 #line 42 "describe.pgc"
146 * Test DESCRIBE with a query producing tuples.
147 * DESCRIPTOR and SQL DESCRIPTOR are NOT the same in
148 * Informix-compat mode.
151 strcpy(msg, "allocate");
152 ECPGallocate_desc(__LINE__, "desc1");
153 #line 51 "describe.pgc"
155 if (sqlca.sqlcode < 0) exit (1);
156 #line 51 "describe.pgc"
158 ECPGallocate_desc(__LINE__, "desc2");
159 #line 52 "describe.pgc"
161 if (sqlca.sqlcode < 0) exit (1);
162 #line 52 "describe.pgc"
165 strcpy(msg, "prepare");
166 { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
167 #line 55 "describe.pgc"
169 if (sqlca.sqlcode < 0) exit (1);}
170 #line 55 "describe.pgc"
173 sqlda1 = sqlda2 = sqlda3 = NULL;
175 strcpy(msg, "describe");
176 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
177 ECPGt_descriptor, "desc1", 1L, 1L, 1L,
178 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
179 #line 60 "describe.pgc"
181 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
182 ECPGt_descriptor, "desc2", 1L, 1L, 1L,
183 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
184 #line 61 "describe.pgc"
187 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
188 ECPGt_sqlda, &sqlda1, 0L, 0L, 0L,
189 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
190 #line 63 "describe.pgc"
192 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
193 ECPGt_sqlda, &sqlda2, 0L, 0L, 0L,
194 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
195 #line 64 "describe.pgc"
197 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id1",
198 ECPGt_sqlda, &sqlda3, 0L, 0L, 0L,
199 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
200 #line 65 "describe.pgc"
205 printf("sqlda1 NULL\n");
211 printf("sqlda2 NULL\n");
217 printf("sqlda3 NULL\n");
221 strcpy(msg, "get descriptor");
222 { ECPGget_desc_header(__LINE__, "desc1", &(count1));
224 #line 86 "describe.pgc"
226 if (sqlca.sqlcode < 0) exit (1);}
227 #line 86 "describe.pgc"
229 { ECPGget_desc_header(__LINE__, "desc1", &(count2));
231 #line 87 "describe.pgc"
233 if (sqlca.sqlcode < 0) exit (1);}
234 #line 87 "describe.pgc"
237 if (count1 != count2)
239 printf("count1 (%d) != count2 (%d)\n", count1, count2);
243 if (count1 != sqlda1->sqld)
245 printf("count1 (%d) != sqlda1->sqld (%d)\n", count1, sqlda1->sqld);
249 if (count1 != sqlda2->sqld)
251 printf("count1 (%d) != sqlda2->sqld (%d)\n", count1, sqlda2->sqld);
255 if (count1 != sqlda3->sqld)
257 printf("count1 (%d) != sqlda3->sqld (%d)\n", count1, sqlda3->sqld);
261 for (i = 1; i <= count1; i++)
263 { ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
264 ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
266 #line 115 "describe.pgc"
268 if (sqlca.sqlcode < 0) exit (1);}
269 #line 115 "describe.pgc"
271 { ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
272 ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
274 #line 116 "describe.pgc"
276 if (sqlca.sqlcode < 0) exit (1);}
277 #line 116 "describe.pgc"
279 printf("%d\n\tfield_name1 '%s'\n\tfield_name2 '%s'\n\t"
280 "sqlda1 '%s'\n\tsqlda2 '%s'\n\tsqlda3 '%s'\n",
281 i, field_name1, field_name2,
282 sqlda1->sqlvar[i-1].sqlname,
283 sqlda2->sqlvar[i-1].sqlname,
284 sqlda3->sqlvar[i-1].sqlname);
287 strcpy(msg, "deallocate");
288 ECPGdeallocate_desc(__LINE__, "desc1");
289 #line 126 "describe.pgc"
291 if (sqlca.sqlcode < 0) exit (1);
292 #line 126 "describe.pgc"
294 ECPGdeallocate_desc(__LINE__, "desc2");
295 #line 127 "describe.pgc"
297 if (sqlca.sqlcode < 0) exit (1);
298 #line 127 "describe.pgc"
304 { ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
305 #line 132 "describe.pgc"
307 if (sqlca.sqlcode < 0) exit (1);}
308 #line 132 "describe.pgc"
311 /* Test DESCRIBE with a query not producing tuples */
313 strcpy(msg, "allocate");
314 ECPGallocate_desc(__LINE__, "desc1");
315 #line 137 "describe.pgc"
317 if (sqlca.sqlcode < 0) exit (1);
318 #line 137 "describe.pgc"
320 ECPGallocate_desc(__LINE__, "desc2");
321 #line 138 "describe.pgc"
323 if (sqlca.sqlcode < 0) exit (1);
324 #line 138 "describe.pgc"
327 strcpy(msg, "prepare");
328 { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt2);
329 #line 141 "describe.pgc"
331 if (sqlca.sqlcode < 0) exit (1);}
332 #line 141 "describe.pgc"
335 sqlda1 = sqlda2 = sqlda3 = NULL;
337 strcpy(msg, "describe");
338 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
339 ECPGt_descriptor, "desc1", 1L, 1L, 1L,
340 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
341 #line 146 "describe.pgc"
343 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
344 ECPGt_descriptor, "desc2", 1L, 1L, 1L,
345 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
346 #line 147 "describe.pgc"
349 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
350 ECPGt_sqlda, &sqlda1, 0L, 0L, 0L,
351 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
352 #line 149 "describe.pgc"
354 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
355 ECPGt_sqlda, &sqlda2, 0L, 0L, 0L,
356 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
357 #line 150 "describe.pgc"
359 { ECPGdescribe(__LINE__, 1, 0, NULL, "st_id2",
360 ECPGt_sqlda, &sqlda3, 0L, 0L, 0L,
361 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
362 #line 151 "describe.pgc"
365 if (sqlda1 == NULL || sqlda2 == NULL || sqlda3 == NULL)
368 strcpy(msg, "get descriptor");
369 { ECPGget_desc_header(__LINE__, "desc1", &(count1));
371 #line 157 "describe.pgc"
373 if (sqlca.sqlcode < 0) exit (1);}
374 #line 157 "describe.pgc"
376 { ECPGget_desc_header(__LINE__, "desc1", &(count2));
378 #line 158 "describe.pgc"
380 if (sqlca.sqlcode < 0) exit (1);}
381 #line 158 "describe.pgc"
384 if (!( count1 == count2 &&
385 count1 == sqlda1->sqld &&
386 count1 == sqlda2->sqld &&
387 count1 == sqlda3->sqld))
390 for (i = 1; i <= count1; i++)
392 { ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
393 ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
395 #line 168 "describe.pgc"
397 if (sqlca.sqlcode < 0) exit (1);}
398 #line 168 "describe.pgc"
400 { ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
401 ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
403 #line 169 "describe.pgc"
405 if (sqlca.sqlcode < 0) exit (1);}
406 #line 169 "describe.pgc"
408 printf("%d\n\tfield_name1 '%s'\n\tfield_name2 '%s'\n\t"
409 "sqlda1 '%s'\n\tsqlda2 '%s'\n\tsqlda3 '%s'\n",
410 i, field_name1, field_name2,
411 sqlda1->sqlvar[i-1].sqlname,
412 sqlda2->sqlvar[i-1].sqlname,
413 sqlda3->sqlvar[i-1].sqlname);
416 strcpy(msg, "deallocate");
417 ECPGdeallocate_desc(__LINE__, "desc1");
418 #line 179 "describe.pgc"
420 if (sqlca.sqlcode < 0) exit (1);
421 #line 179 "describe.pgc"
423 ECPGdeallocate_desc(__LINE__, "desc2");
424 #line 180 "describe.pgc"
426 if (sqlca.sqlcode < 0) exit (1);
427 #line 180 "describe.pgc"
433 { ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
434 #line 185 "describe.pgc"
436 if (sqlca.sqlcode < 0) exit (1);}
437 #line 185 "describe.pgc"
443 { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table descr_t1", ECPGt_EOIT, ECPGt_EORT);
444 #line 190 "describe.pgc"
446 if (sqlca.sqlcode < 0) exit (1);}
447 #line 190 "describe.pgc"
450 strcpy(msg, "commit");
451 { ECPGtrans(__LINE__, NULL, "commit");
452 #line 193 "describe.pgc"
454 if (sqlca.sqlcode < 0) exit (1);}
455 #line 193 "describe.pgc"
458 strcpy(msg, "disconnect");
459 { ECPGdisconnect(__LINE__, "CURRENT");
460 #line 196 "describe.pgc"
462 if (sqlca.sqlcode < 0) exit (1);}
463 #line 196 "describe.pgc"