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 "describe.pgc"
12 #include <stdlib.h>
13 #include <string.h>
14 
15 
16 #line 1 "regression.h"
17 
18 
19 
20 
21 
22 
23 #line 4 "describe.pgc"
24 
25 
26 #line 1 "sqlda.h"
27 #ifndef ECPG_SQLDA_H
28 #define ECPG_SQLDA_H
29 
30 #ifdef _ECPG_INFORMIX_H
31 
32 #include "sqlda-compat.h"
33 typedef struct sqlvar_compat sqlvar_t;
34 typedef struct sqlda_compat sqlda_t;
35 
36 #else
37 
38 #include "sqlda-native.h"
39 typedef struct sqlvar_struct sqlvar_t;
40 typedef struct sqlda_struct sqlda_t;
41 
42 #endif
43 
44 #endif							/* ECPG_SQLDA_H */
45 
46 #line 5 "describe.pgc"
47 
48 
49 /* exec sql whenever sqlerror  stop ; */
50 #line 7 "describe.pgc"
51 
52 
53 sqlda_t	*sqlda1, *sqlda2, *sqlda3;
54 
55 int
main(void)56 main (void)
57 {
58 /* exec sql begin declare section */
59 
60 
61 
62 
63 
64 
65 #line 15 "describe.pgc"
66  char * stmt1 = "SELECT id, t FROM descr_t1" ;
67 
68 #line 16 "describe.pgc"
69  char * stmt2 = "SELECT id, t FROM descr_t1 WHERE id = -1" ;
70 
71 #line 17 "describe.pgc"
72  int i , count1 , count2 ;
73 
74 #line 18 "describe.pgc"
75  char field_name1 [ 30 ] = "not set" ;
76 
77 #line 19 "describe.pgc"
78  char field_name2 [ 30 ] = "not set" ;
79 /* exec sql end declare section */
80 #line 20 "describe.pgc"
81 
82 
83 	char msg[128];
84 
85 	ECPGdebug(1, stderr);
86 
87 	strcpy(msg, "connect");
88 	{ ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , NULL, 0);
89 #line 27 "describe.pgc"
90 
91 if (sqlca.sqlcode < 0) exit (1);}
92 #line 27 "describe.pgc"
93 
94 
95 	strcpy(msg, "set");
96 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
97 #line 30 "describe.pgc"
98 
99 if (sqlca.sqlcode < 0) exit (1);}
100 #line 30 "describe.pgc"
101 
102 
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"
106 
107 if (sqlca.sqlcode < 0) exit (1);}
108 #line 33 "describe.pgc"
109 
110 
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"
114 
115 if (sqlca.sqlcode < 0) exit (1);}
116 #line 36 "describe.pgc"
117 
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"
120 
121 if (sqlca.sqlcode < 0) exit (1);}
122 #line 37 "describe.pgc"
123 
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"
126 
127 if (sqlca.sqlcode < 0) exit (1);}
128 #line 38 "describe.pgc"
129 
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"
132 
133 if (sqlca.sqlcode < 0) exit (1);}
134 #line 39 "describe.pgc"
135 
136 
137 	strcpy(msg, "commit");
138 	{ ECPGtrans(__LINE__, NULL, "commit");
139 #line 42 "describe.pgc"
140 
141 if (sqlca.sqlcode < 0) exit (1);}
142 #line 42 "describe.pgc"
143 
144 
145 	/*
146 	 * Test DESCRIBE with a query producing tuples.
147 	 * DESCRIPTOR and SQL DESCRIPTOR are NOT the same in
148 	 * Informix-compat mode.
149 	 */
150 
151 	strcpy(msg, "allocate");
152 	ECPGallocate_desc(__LINE__, "desc1");
153 #line 51 "describe.pgc"
154 
155 if (sqlca.sqlcode < 0) exit (1);
156 #line 51 "describe.pgc"
157 
158 	ECPGallocate_desc(__LINE__, "desc2");
159 #line 52 "describe.pgc"
160 
161 if (sqlca.sqlcode < 0) exit (1);
162 #line 52 "describe.pgc"
163 
164 
165 	strcpy(msg, "prepare");
166 	{ ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
167 #line 55 "describe.pgc"
168 
169 if (sqlca.sqlcode < 0) exit (1);}
170 #line 55 "describe.pgc"
171 
172 
173 	sqlda1 = sqlda2 = sqlda3 = NULL;
174 
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"
180 
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"
185 
186 
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"
191 
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"
196 
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"
201 
202 
203 	if (sqlda1 == NULL)
204 	{
205 		printf("sqlda1 NULL\n");
206 		exit(1);
207 	}
208 
209 	if (sqlda2 == NULL)
210 	{
211 		printf("sqlda2 NULL\n");
212 		exit(1);
213 	}
214 
215 	if (sqlda3 == NULL)
216 	{
217 		printf("sqlda3 NULL\n");
218 		exit(1);
219 	}
220 
221 	strcpy(msg, "get descriptor");
222 	{ ECPGget_desc_header(__LINE__, "desc1", &(count1));
223 
224 #line 86 "describe.pgc"
225 
226 if (sqlca.sqlcode < 0) exit (1);}
227 #line 86 "describe.pgc"
228 
229 	{ ECPGget_desc_header(__LINE__, "desc1", &(count2));
230 
231 #line 87 "describe.pgc"
232 
233 if (sqlca.sqlcode < 0) exit (1);}
234 #line 87 "describe.pgc"
235 
236 
237 	if (count1 != count2)
238 	{
239 		printf("count1 (%d) != count2 (%d)\n", count1, count2);
240 		exit(1);
241 	}
242 
243 	if (count1 != sqlda1->sqld)
244 	{
245 		printf("count1 (%d) != sqlda1->sqld (%d)\n", count1, sqlda1->sqld);
246 		exit(1);
247 	}
248 
249 	if (count1 != sqlda2->sqld)
250 	{
251 		printf("count1 (%d) != sqlda2->sqld (%d)\n", count1, sqlda2->sqld);
252 		exit(1);
253 	}
254 
255 	if (count1 != sqlda3->sqld)
256 	{
257 		printf("count1 (%d) != sqlda3->sqld (%d)\n", count1, sqlda3->sqld);
258 		exit(1);
259 	}
260 
261 	for (i = 1; i <= count1; i++)
262 	{
263 		{ ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
264 	ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
265 
266 #line 115 "describe.pgc"
267 
268 if (sqlca.sqlcode < 0) exit (1);}
269 #line 115 "describe.pgc"
270 
271 		{ ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
272 	ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
273 
274 #line 116 "describe.pgc"
275 
276 if (sqlca.sqlcode < 0) exit (1);}
277 #line 116 "describe.pgc"
278 
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);
285 	}
286 
287 	strcpy(msg, "deallocate");
288 	ECPGdeallocate_desc(__LINE__, "desc1");
289 #line 126 "describe.pgc"
290 
291 if (sqlca.sqlcode < 0) exit (1);
292 #line 126 "describe.pgc"
293 
294 	ECPGdeallocate_desc(__LINE__, "desc2");
295 #line 127 "describe.pgc"
296 
297 if (sqlca.sqlcode < 0) exit (1);
298 #line 127 "describe.pgc"
299 
300 	free(sqlda1);
301 	free(sqlda2);
302 	free(sqlda3);
303 
304 	{ ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
305 #line 132 "describe.pgc"
306 
307 if (sqlca.sqlcode < 0) exit (1);}
308 #line 132 "describe.pgc"
309 
310 
311 	/* Test DESCRIBE with a query not producing tuples */
312 
313 	strcpy(msg, "allocate");
314 	ECPGallocate_desc(__LINE__, "desc1");
315 #line 137 "describe.pgc"
316 
317 if (sqlca.sqlcode < 0) exit (1);
318 #line 137 "describe.pgc"
319 
320 	ECPGallocate_desc(__LINE__, "desc2");
321 #line 138 "describe.pgc"
322 
323 if (sqlca.sqlcode < 0) exit (1);
324 #line 138 "describe.pgc"
325 
326 
327 	strcpy(msg, "prepare");
328 	{ ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt2);
329 #line 141 "describe.pgc"
330 
331 if (sqlca.sqlcode < 0) exit (1);}
332 #line 141 "describe.pgc"
333 
334 
335 	sqlda1 = sqlda2 = sqlda3 = NULL;
336 
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"
342 
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"
347 
348 
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"
353 
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"
358 
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"
363 
364 
365 	if (sqlda1 == NULL || sqlda2 == NULL || sqlda3 == NULL)
366 		exit(1);
367 
368 	strcpy(msg, "get descriptor");
369 	{ ECPGget_desc_header(__LINE__, "desc1", &(count1));
370 
371 #line 157 "describe.pgc"
372 
373 if (sqlca.sqlcode < 0) exit (1);}
374 #line 157 "describe.pgc"
375 
376 	{ ECPGget_desc_header(__LINE__, "desc1", &(count2));
377 
378 #line 158 "describe.pgc"
379 
380 if (sqlca.sqlcode < 0) exit (1);}
381 #line 158 "describe.pgc"
382 
383 
384 	if (!(	count1 == count2 &&
385 		count1 == sqlda1->sqld &&
386 		count1 == sqlda2->sqld &&
387 		count1 == sqlda3->sqld))
388 		exit(1);
389 
390 	for (i = 1; i <= count1; i++)
391 	{
392 		{ ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
393 	ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
394 
395 #line 168 "describe.pgc"
396 
397 if (sqlca.sqlcode < 0) exit (1);}
398 #line 168 "describe.pgc"
399 
400 		{ ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
401 	ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
402 
403 #line 169 "describe.pgc"
404 
405 if (sqlca.sqlcode < 0) exit (1);}
406 #line 169 "describe.pgc"
407 
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);
414 	}
415 
416 	strcpy(msg, "deallocate");
417 	ECPGdeallocate_desc(__LINE__, "desc1");
418 #line 179 "describe.pgc"
419 
420 if (sqlca.sqlcode < 0) exit (1);
421 #line 179 "describe.pgc"
422 
423 	ECPGdeallocate_desc(__LINE__, "desc2");
424 #line 180 "describe.pgc"
425 
426 if (sqlca.sqlcode < 0) exit (1);
427 #line 180 "describe.pgc"
428 
429 	free(sqlda1);
430 	free(sqlda2);
431 	free(sqlda3);
432 
433 	{ ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
434 #line 185 "describe.pgc"
435 
436 if (sqlca.sqlcode < 0) exit (1);}
437 #line 185 "describe.pgc"
438 
439 
440 	/* End test */
441 
442 	strcpy(msg, "drop");
443 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table descr_t1", ECPGt_EOIT, ECPGt_EORT);
444 #line 190 "describe.pgc"
445 
446 if (sqlca.sqlcode < 0) exit (1);}
447 #line 190 "describe.pgc"
448 
449 
450 	strcpy(msg, "commit");
451 	{ ECPGtrans(__LINE__, NULL, "commit");
452 #line 193 "describe.pgc"
453 
454 if (sqlca.sqlcode < 0) exit (1);}
455 #line 193 "describe.pgc"
456 
457 
458 	strcpy(msg, "disconnect");
459 	{ ECPGdisconnect(__LINE__, "CURRENT");
460 #line 196 "describe.pgc"
461 
462 if (sqlca.sqlcode < 0) exit (1);}
463 #line 196 "describe.pgc"
464 
465 
466 	return (0);
467 }
468