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 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8
9 #line 1 "describe.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12
13
14 #line 1 "regression.h"
15
16
17
18
19
20
21 #line 4 "describe.pgc"
22
23
24 /* exec sql whenever sqlerror stop ; */
25 #line 6 "describe.pgc"
26
27
28 int
main(void)29 main (void)
30 {
31 /* exec sql begin declare section */
32
33
34
35
36
37
38
39
40 #line 12 "describe.pgc"
41 char * stmt1 = "SELECT id, t FROM t1" ;
42
43 #line 13 "describe.pgc"
44 char * stmt2 = "SELECT id, t FROM t1 WHERE id = -1" ;
45
46 #line 14 "describe.pgc"
47 int i , count1 , count2 , count3 , count4 ;
48
49 #line 15 "describe.pgc"
50 char field_name1 [ 30 ] = "not set" ;
51
52 #line 16 "describe.pgc"
53 char field_name2 [ 30 ] = "not set" ;
54
55 #line 17 "describe.pgc"
56 char field_name3 [ 30 ] = "not set" ;
57
58 #line 18 "describe.pgc"
59 char field_name4 [ 30 ] = "not set" ;
60 /* exec sql end declare section */
61 #line 19 "describe.pgc"
62
63
64 char msg[128];
65
66 ECPGdebug(1, stderr);
67
68 strcpy(msg, "connect");
69 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
70 #line 26 "describe.pgc"
71
72 if (sqlca.sqlcode < 0) exit (1);}
73 #line 26 "describe.pgc"
74
75
76 strcpy(msg, "set");
77 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
78 #line 29 "describe.pgc"
79
80 if (sqlca.sqlcode < 0) exit (1);}
81 #line 29 "describe.pgc"
82
83
84 strcpy(msg, "create");
85 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id serial primary key , t text )", ECPGt_EOIT, ECPGt_EORT);
86 #line 32 "describe.pgc"
87
88 if (sqlca.sqlcode < 0) exit (1);}
89 #line 32 "describe.pgc"
90
91
92 strcpy(msg, "insert");
93 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 ( id , t ) values ( default , 'a' )", ECPGt_EOIT, ECPGt_EORT);
94 #line 35 "describe.pgc"
95
96 if (sqlca.sqlcode < 0) exit (1);}
97 #line 35 "describe.pgc"
98
99 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 ( id , t ) values ( default , 'b' )", ECPGt_EOIT, ECPGt_EORT);
100 #line 36 "describe.pgc"
101
102 if (sqlca.sqlcode < 0) exit (1);}
103 #line 36 "describe.pgc"
104
105 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 ( id , t ) values ( default , 'c' )", ECPGt_EOIT, ECPGt_EORT);
106 #line 37 "describe.pgc"
107
108 if (sqlca.sqlcode < 0) exit (1);}
109 #line 37 "describe.pgc"
110
111 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 ( id , t ) values ( default , 'd' )", ECPGt_EOIT, ECPGt_EORT);
112 #line 38 "describe.pgc"
113
114 if (sqlca.sqlcode < 0) exit (1);}
115 #line 38 "describe.pgc"
116
117
118 strcpy(msg, "commit");
119 { ECPGtrans(__LINE__, NULL, "commit");
120 #line 41 "describe.pgc"
121
122 if (sqlca.sqlcode < 0) exit (1);}
123 #line 41 "describe.pgc"
124
125
126 /*
127 * Test DESCRIBE with a query producing tuples.
128 * DESCRIPTOR and SQL DESCRIPTOR are the same in native mode.
129 */
130
131 strcpy(msg, "allocate");
132 ECPGallocate_desc(__LINE__, "desc1");
133 #line 49 "describe.pgc"
134
135 if (sqlca.sqlcode < 0) exit (1);
136 #line 49 "describe.pgc"
137
138 ECPGallocate_desc(__LINE__, "desc2");
139 #line 50 "describe.pgc"
140
141 if (sqlca.sqlcode < 0) exit (1);
142 #line 50 "describe.pgc"
143
144 ECPGallocate_desc(__LINE__, "desc3");
145 #line 51 "describe.pgc"
146
147 if (sqlca.sqlcode < 0) exit (1);
148 #line 51 "describe.pgc"
149
150 ECPGallocate_desc(__LINE__, "desc4");
151 #line 52 "describe.pgc"
152
153 if (sqlca.sqlcode < 0) exit (1);
154 #line 52 "describe.pgc"
155
156
157 strcpy(msg, "prepare");
158 { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
159 #line 55 "describe.pgc"
160
161 if (sqlca.sqlcode < 0) exit (1);}
162 #line 55 "describe.pgc"
163
164
165 strcpy(msg, "describe");
166 { ECPGdescribe(__LINE__, 0, NULL, "st_id1",
167 ECPGt_descriptor, "desc1", 0L, 0L, 0L,
168 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
169 #line 58 "describe.pgc"
170
171 { ECPGdescribe(__LINE__, 0, NULL, "st_id1",
172 ECPGt_descriptor, "desc2", 0L, 0L, 0L,
173 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
174 #line 59 "describe.pgc"
175
176 { ECPGdescribe(__LINE__, 0, NULL, "st_id1",
177 ECPGt_descriptor, "desc3", 0L, 0L, 0L,
178 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
179 #line 60 "describe.pgc"
180
181 { ECPGdescribe(__LINE__, 0, NULL, "st_id1",
182 ECPGt_descriptor, "desc4", 0L, 0L, 0L,
183 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
184 #line 61 "describe.pgc"
185
186
187 strcpy(msg, "get descriptor");
188 { ECPGget_desc_header(__LINE__, "desc1", &(count1));
189
190 #line 64 "describe.pgc"
191
192 if (sqlca.sqlcode < 0) exit (1);}
193 #line 64 "describe.pgc"
194
195 { ECPGget_desc_header(__LINE__, "desc2", &(count2));
196
197 #line 65 "describe.pgc"
198
199 if (sqlca.sqlcode < 0) exit (1);}
200 #line 65 "describe.pgc"
201
202 { ECPGget_desc_header(__LINE__, "desc3", &(count3));
203
204 #line 66 "describe.pgc"
205
206 if (sqlca.sqlcode < 0) exit (1);}
207 #line 66 "describe.pgc"
208
209 { ECPGget_desc_header(__LINE__, "desc4", &(count4));
210
211 #line 67 "describe.pgc"
212
213 if (sqlca.sqlcode < 0) exit (1);}
214 #line 67 "describe.pgc"
215
216
217 if (!(count1 == count2 && count1 == count3 && count1 == count4))
218 exit(1);
219
220 for (i = 1; i <= count1; i++)
221 {
222 { ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
223 ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
224
225 #line 74 "describe.pgc"
226
227 if (sqlca.sqlcode < 0) exit (1);}
228 #line 74 "describe.pgc"
229
230 { ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
231 ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
232
233 #line 75 "describe.pgc"
234
235 if (sqlca.sqlcode < 0) exit (1);}
236 #line 75 "describe.pgc"
237
238 { ECPGget_desc(__LINE__, "desc3", i,ECPGd_name,
239 ECPGt_char,(field_name3),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
240
241 #line 76 "describe.pgc"
242
243 if (sqlca.sqlcode < 0) exit (1);}
244 #line 76 "describe.pgc"
245
246 { ECPGget_desc(__LINE__, "desc4", i,ECPGd_name,
247 ECPGt_char,(field_name4),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
248
249 #line 77 "describe.pgc"
250
251 if (sqlca.sqlcode < 0) exit (1);}
252 #line 77 "describe.pgc"
253
254 printf("field_name 1 '%s' 2 '%s' 3 '%s' 4 '%s'\n",
255 field_name1, field_name2, field_name3, field_name4);
256 }
257
258 strcpy(msg, "deallocate");
259 ECPGdeallocate_desc(__LINE__, "desc1");
260 #line 83 "describe.pgc"
261
262 if (sqlca.sqlcode < 0) exit (1);
263 #line 83 "describe.pgc"
264
265 ECPGdeallocate_desc(__LINE__, "desc2");
266 #line 84 "describe.pgc"
267
268 if (sqlca.sqlcode < 0) exit (1);
269 #line 84 "describe.pgc"
270
271 ECPGdeallocate_desc(__LINE__, "desc3");
272 #line 85 "describe.pgc"
273
274 if (sqlca.sqlcode < 0) exit (1);
275 #line 85 "describe.pgc"
276
277 ECPGdeallocate_desc(__LINE__, "desc4");
278 #line 86 "describe.pgc"
279
280 if (sqlca.sqlcode < 0) exit (1);
281 #line 86 "describe.pgc"
282
283
284 { ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
285 #line 88 "describe.pgc"
286
287 if (sqlca.sqlcode < 0) exit (1);}
288 #line 88 "describe.pgc"
289
290
291 /* Test DESCRIBE with a query not producing tuples */
292
293 strcpy(msg, "allocate");
294 ECPGallocate_desc(__LINE__, "desc1");
295 #line 93 "describe.pgc"
296
297 if (sqlca.sqlcode < 0) exit (1);
298 #line 93 "describe.pgc"
299
300 ECPGallocate_desc(__LINE__, "desc2");
301 #line 94 "describe.pgc"
302
303 if (sqlca.sqlcode < 0) exit (1);
304 #line 94 "describe.pgc"
305
306 ECPGallocate_desc(__LINE__, "desc3");
307 #line 95 "describe.pgc"
308
309 if (sqlca.sqlcode < 0) exit (1);
310 #line 95 "describe.pgc"
311
312 ECPGallocate_desc(__LINE__, "desc4");
313 #line 96 "describe.pgc"
314
315 if (sqlca.sqlcode < 0) exit (1);
316 #line 96 "describe.pgc"
317
318
319 strcpy(msg, "prepare");
320 { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt2);
321 #line 99 "describe.pgc"
322
323 if (sqlca.sqlcode < 0) exit (1);}
324 #line 99 "describe.pgc"
325
326
327 strcpy(msg, "describe");
328 { ECPGdescribe(__LINE__, 0, NULL, "st_id2",
329 ECPGt_descriptor, "desc1", 0L, 0L, 0L,
330 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
331 #line 102 "describe.pgc"
332
333 { ECPGdescribe(__LINE__, 0, NULL, "st_id2",
334 ECPGt_descriptor, "desc2", 0L, 0L, 0L,
335 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
336 #line 103 "describe.pgc"
337
338 { ECPGdescribe(__LINE__, 0, NULL, "st_id2",
339 ECPGt_descriptor, "desc3", 0L, 0L, 0L,
340 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
341 #line 104 "describe.pgc"
342
343 { ECPGdescribe(__LINE__, 0, NULL, "st_id2",
344 ECPGt_descriptor, "desc4", 0L, 0L, 0L,
345 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
346 #line 105 "describe.pgc"
347
348
349 strcpy(msg, "get descriptor");
350 { ECPGget_desc_header(__LINE__, "desc1", &(count1));
351
352 #line 108 "describe.pgc"
353
354 if (sqlca.sqlcode < 0) exit (1);}
355 #line 108 "describe.pgc"
356
357 { ECPGget_desc_header(__LINE__, "desc2", &(count2));
358
359 #line 109 "describe.pgc"
360
361 if (sqlca.sqlcode < 0) exit (1);}
362 #line 109 "describe.pgc"
363
364 { ECPGget_desc_header(__LINE__, "desc3", &(count3));
365
366 #line 110 "describe.pgc"
367
368 if (sqlca.sqlcode < 0) exit (1);}
369 #line 110 "describe.pgc"
370
371 { ECPGget_desc_header(__LINE__, "desc4", &(count4));
372
373 #line 111 "describe.pgc"
374
375 if (sqlca.sqlcode < 0) exit (1);}
376 #line 111 "describe.pgc"
377
378
379 if (!(count1 == count2 && count1 == count3 && count1 == count4))
380 exit(1);
381
382 for (i = 1; i <= count1; i++)
383 {
384 { ECPGget_desc(__LINE__, "desc1", i,ECPGd_name,
385 ECPGt_char,(field_name1),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
386
387 #line 118 "describe.pgc"
388
389 if (sqlca.sqlcode < 0) exit (1);}
390 #line 118 "describe.pgc"
391
392 { ECPGget_desc(__LINE__, "desc2", i,ECPGd_name,
393 ECPGt_char,(field_name2),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
394
395 #line 119 "describe.pgc"
396
397 if (sqlca.sqlcode < 0) exit (1);}
398 #line 119 "describe.pgc"
399
400 { ECPGget_desc(__LINE__, "desc3", i,ECPGd_name,
401 ECPGt_char,(field_name3),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
402
403 #line 120 "describe.pgc"
404
405 if (sqlca.sqlcode < 0) exit (1);}
406 #line 120 "describe.pgc"
407
408 { ECPGget_desc(__LINE__, "desc4", i,ECPGd_name,
409 ECPGt_char,(field_name4),(long)30,(long)1,(30)*sizeof(char), ECPGd_EODT);
410
411 #line 121 "describe.pgc"
412
413 if (sqlca.sqlcode < 0) exit (1);}
414 #line 121 "describe.pgc"
415
416 printf("field_name 1 '%s' 2 '%s' 3 '%s' 4 '%s'\n",
417 field_name1, field_name2, field_name3, field_name4);
418 }
419
420 strcpy(msg, "deallocate");
421 ECPGdeallocate_desc(__LINE__, "desc1");
422 #line 127 "describe.pgc"
423
424 if (sqlca.sqlcode < 0) exit (1);
425 #line 127 "describe.pgc"
426
427 ECPGdeallocate_desc(__LINE__, "desc2");
428 #line 128 "describe.pgc"
429
430 if (sqlca.sqlcode < 0) exit (1);
431 #line 128 "describe.pgc"
432
433 ECPGdeallocate_desc(__LINE__, "desc3");
434 #line 129 "describe.pgc"
435
436 if (sqlca.sqlcode < 0) exit (1);
437 #line 129 "describe.pgc"
438
439 ECPGdeallocate_desc(__LINE__, "desc4");
440 #line 130 "describe.pgc"
441
442 if (sqlca.sqlcode < 0) exit (1);
443 #line 130 "describe.pgc"
444
445
446 { ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
447 #line 132 "describe.pgc"
448
449 if (sqlca.sqlcode < 0) exit (1);}
450 #line 132 "describe.pgc"
451
452
453
454 /* End test */
455
456 strcpy(msg, "drop");
457 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
458 #line 138 "describe.pgc"
459
460 if (sqlca.sqlcode < 0) exit (1);}
461 #line 138 "describe.pgc"
462
463
464 strcpy(msg, "commit");
465 { ECPGtrans(__LINE__, NULL, "commit");
466 #line 141 "describe.pgc"
467
468 if (sqlca.sqlcode < 0) exit (1);}
469 #line 141 "describe.pgc"
470
471
472 strcpy(msg, "disconnect");
473 { ECPGdisconnect(__LINE__, "CURRENT");
474 #line 144 "describe.pgc"
475
476 if (sqlca.sqlcode < 0) exit (1);}
477 #line 144 "describe.pgc"
478
479
480 return (0);
481 }
482