PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define ECPG_SQLDA_H

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

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

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

Referenced by main().

Typedef Documentation

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

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

Function Documentation

int main ( void  )

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

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(), free, i, NULL, sqlca, sqlda_struct::sqld, sqlvar_struct::sqlname, and sqlda_struct::sqlvar.

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 
89 if (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 
97 if (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 
105 if (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 
113 if (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 
119 if (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 
125 if (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 
131 if (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 
139 if (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 
153 if (sqlca.sqlcode < 0) exit (1);
154 #line 51 "describe.pgc"
155 
156  ECPGallocate_desc(__LINE__, "desc2");
157 #line 52 "describe.pgc"
158 
159 if (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 
167 if (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 
224 if (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 
231 if (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 
266 if (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 
274 if (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,
280  sqlda1->sqlvar[i-1].sqlname.data,
281  sqlda2->sqlvar[i-1].sqlname.data,
282  sqlda3->sqlvar[i-1].sqlname.data);
283  }
284 
285  strcpy(msg, "deallocate");
286  ECPGdeallocate_desc(__LINE__, "desc1");
287 #line 126 "describe.pgc"
288 
289 if (sqlca.sqlcode < 0) exit (1);
290 #line 126 "describe.pgc"
291 
292  ECPGdeallocate_desc(__LINE__, "desc2");
293 #line 127 "describe.pgc"
294 
295 if (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 
305 if (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 
315 if (sqlca.sqlcode < 0) exit (1);
316 #line 137 "describe.pgc"
317 
318  ECPGallocate_desc(__LINE__, "desc2");
319 #line 138 "describe.pgc"
320 
321 if (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 
329 if (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 
371 if (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 
378 if (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 
395 if (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 
403 if (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,
409  sqlda1->sqlvar[i-1].sqlname.data,
410  sqlda2->sqlvar[i-1].sqlname.data,
411  sqlda3->sqlvar[i-1].sqlname.data);
412  }
413 
414  strcpy(msg, "deallocate");
415  ECPGdeallocate_desc(__LINE__, "desc1");
416 #line 179 "describe.pgc"
417 
418 if (sqlca.sqlcode < 0) exit (1);
419 #line 179 "describe.pgc"
420 
421  ECPGdeallocate_desc(__LINE__, "desc2");
422 #line 180 "describe.pgc"
423 
424 if (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 
434 if (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 
444 if (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 
452 if (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 
460 if (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:669
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:759
#define sqlca
Definition: sqlca.h:59
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:2031
sqlda_t * sqlda1
Definition: sql-describe.c:51
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:161
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
#define ECPGdebug(X, Y)
Definition: sql-describe.c:7
bool ECPGdescribe(int line, int compat, bool input, const char *connection_name, const char *stmt_name,...)
Definition: descriptor.c:814
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
sqlda_t * sqlda2
Definition: sql-describe.c:51
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:245
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition: prepare.c:253
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition: descriptor.c:91
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:712
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
int i
sqlda_t * sqlda3
Definition: sql-describe.c:51
struct sqlname sqlname
Definition: sqlda-native.h:30

Variable Documentation

sqlda_t* sqlda1

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

sqlda_t * sqlda2

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

sqlda_t * sqlda3

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