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

Go to the source code of this file.

Macros

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

Typedefs

typedef struct sqlvar_struct sqlvar_t
 
typedef struct sqlda_struct sqlda_t
 

Functions

int main (void)
 

Variables

sqlda_tsqlda1
 
sqlda_tsqlda2
 
sqlda_tsqlda3
 

Macro Definition Documentation

◆ ECPG_SQLDA_H

#define ECPG_SQLDA_H

Definition at line 26 of file sql-describe.c.

◆ ECPGdebug

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

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

Typedef Documentation

◆ sqlda_t

typedef struct sqlda_struct sqlda_t

Definition at line 38 of file sql-describe.c.

◆ sqlvar_t

typedef struct sqlvar_struct sqlvar_t

Definition at line 37 of file sql-describe.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 54 of file sql-describe.c.

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

References sqlname::data, 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, ECPGt_sqlda, ECPGtrans(), exit(), free, i, printf, sqlca, sqlda_struct::sqld, sqlda1, sqlda2, sqlda3, sqlvar_struct::sqlname, and sqlda_struct::sqlvar.

Variable Documentation

◆ sqlda1

sqlda_t* sqlda1

Definition at line 51 of file sql-describe.c.

Referenced by main().

◆ sqlda2

sqlda_t * sqlda2

Definition at line 51 of file sql-describe.c.

Referenced by main().

◆ sqlda3

sqlda_t * sqlda3

Definition at line 51 of file sql-describe.c.

Referenced by main().