PostgreSQL Source Code git master
preproc-describe.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for preproc-describe.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file preproc-describe.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 29 of file preproc-describe.c.

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
72if (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
80if (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
88if (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
96if (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
102if (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
108if (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
114if (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
122if (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
135if (sqlca.sqlcode < 0) exit (1);
136#line 49 "describe.pgc"
137
138 ECPGallocate_desc(__LINE__, "desc2");
139#line 50 "describe.pgc"
140
141if (sqlca.sqlcode < 0) exit (1);
142#line 50 "describe.pgc"
143
144 ECPGallocate_desc(__LINE__, "desc3");
145#line 51 "describe.pgc"
146
147if (sqlca.sqlcode < 0) exit (1);
148#line 51 "describe.pgc"
149
150 ECPGallocate_desc(__LINE__, "desc4");
151#line 52 "describe.pgc"
152
153if (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
161if (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
192if (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
199if (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
206if (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
213if (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
227if (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
235if (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
243if (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
251if (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
262if (sqlca.sqlcode < 0) exit (1);
263#line 83 "describe.pgc"
264
265 ECPGdeallocate_desc(__LINE__, "desc2");
266#line 84 "describe.pgc"
267
268if (sqlca.sqlcode < 0) exit (1);
269#line 84 "describe.pgc"
270
271 ECPGdeallocate_desc(__LINE__, "desc3");
272#line 85 "describe.pgc"
273
274if (sqlca.sqlcode < 0) exit (1);
275#line 85 "describe.pgc"
276
277 ECPGdeallocate_desc(__LINE__, "desc4");
278#line 86 "describe.pgc"
279
280if (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
287if (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
297if (sqlca.sqlcode < 0) exit (1);
298#line 93 "describe.pgc"
299
300 ECPGallocate_desc(__LINE__, "desc2");
301#line 94 "describe.pgc"
302
303if (sqlca.sqlcode < 0) exit (1);
304#line 94 "describe.pgc"
305
306 ECPGallocate_desc(__LINE__, "desc3");
307#line 95 "describe.pgc"
308
309if (sqlca.sqlcode < 0) exit (1);
310#line 95 "describe.pgc"
311
312 ECPGallocate_desc(__LINE__, "desc4");
313#line 96 "describe.pgc"
314
315if (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
323if (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
354if (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
361if (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
368if (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
375if (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
389if (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
397if (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
405if (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
413if (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
424if (sqlca.sqlcode < 0) exit (1);
425#line 127 "describe.pgc"
426
427 ECPGdeallocate_desc(__LINE__, "desc2");
428#line 128 "describe.pgc"
429
430if (sqlca.sqlcode < 0) exit (1);
431#line 128 "describe.pgc"
432
433 ECPGdeallocate_desc(__LINE__, "desc3");
434#line 129 "describe.pgc"
435
436if (sqlca.sqlcode < 0) exit (1);
437#line 129 "describe.pgc"
438
439 ECPGdeallocate_desc(__LINE__, "desc4");
440#line 130 "describe.pgc"
441
442if (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
449if (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
460if (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
468if (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
476if (sqlca.sqlcode < 0) exit (1);}
477#line 144 "describe.pgc"
478
479
480 return 0;
481}
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
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:748
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:234
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:792
bool ECPGdescribe(int line, int compat, bool input, const char *connection_name, const char *stmt_name,...)
Definition: descriptor.c:847
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition: descriptor.c:84
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_descriptor
Definition: ecpgtype.h:59
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGd_name
Definition: ecpgtype.h:80
@ ECPGd_EODT
Definition: ecpgtype.h:88
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
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
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 ECPGdebug(X, Y)
#define sqlca
Definition: sqlca.h:59

References ECPGallocate_desc(), ECPGconnect(), ECPGd_EODT, ECPGd_name, ECPGdeallocate(), ECPGdeallocate_desc(), ECPGdebug, ECPGdescribe(), ECPGdisconnect(), ECPGdo(), ECPGget_desc(), ECPGget_desc_header(), ECPGprepare(), ECPGst_normal, ECPGt_char, ECPGt_descriptor, ECPGt_EOIT, ECPGt_EORT, ECPGt_NO_INDICATOR, ECPGtrans(), exit(), i, printf, and sqlca.