PostgreSQL Source Code  git master
sql-sqlda.c
Go to the documentation of this file.
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 "sqlda.pgc"
10 #include <stdlib.h>
11 #include <string.h>
12 #include <limits.h>
13 #include "ecpg_config.h"
14 
15 
16 #line 1 "regression.h"
17 
18 
19 
20 
21 
22 
23 #line 6 "sqlda.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 7 "sqlda.pgc"
47 
48 
49 #line 1 "pgtypes_numeric.h"
50 #ifndef PGTYPES_NUMERIC
51 #define PGTYPES_NUMERIC
52 
53 #define NUMERIC_POS 0x0000
54 #define NUMERIC_NEG 0x4000
55 #define NUMERIC_NAN 0xC000
56 #define NUMERIC_NULL 0xF000
57 #define NUMERIC_MAX_PRECISION 1000
58 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
59 #define NUMERIC_MIN_DISPLAY_SCALE 0
60 #define NUMERIC_MIN_SIG_DIGITS 16
61 
62 #define DECSIZE 30
63 
64 typedef unsigned char NumericDigit;
65 typedef struct
66 {
67  int ndigits; /* number of digits in digits[] - can be 0! */
68  int weight; /* weight of first digit */
69  int rscale; /* result scale */
70  int dscale; /* display scale */
71  int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
72  NumericDigit *buf; /* start of alloc'd space for digits[] */
73  NumericDigit *digits; /* decimal digits */
74 } numeric;
75 
76 typedef struct
77 {
78  int ndigits; /* number of digits in digits[] - can be 0! */
79  int weight; /* weight of first digit */
80  int rscale; /* result scale */
81  int dscale; /* display scale */
82  int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
83  NumericDigit digits[DECSIZE]; /* decimal digits */
84 } decimal;
85 
86 #ifdef __cplusplus
87 extern "C"
88 {
89 #endif
90 
95 numeric *PGTYPESnumeric_from_asc(char *, char **);
96 char *PGTYPESnumeric_to_asc(numeric *, int);
102 int PGTYPESnumeric_from_int(signed int, numeric *);
103 int PGTYPESnumeric_from_long(signed long int, numeric *);
105 int PGTYPESnumeric_from_double(double, numeric *);
106 int PGTYPESnumeric_to_double(numeric *, double *);
107 int PGTYPESnumeric_to_int(numeric *, int *);
108 int PGTYPESnumeric_to_long(numeric *, long *);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* PGTYPES_NUMERIC */
117 
118 #line 8 "sqlda.pgc"
119 
120 
121 /* exec sql whenever sqlerror stop ; */
122 #line 10 "sqlda.pgc"
123 
124 
125 /* These shouldn't be under DECLARE SECTION */
127 
128 static void
130 {
131  int i;
132 
133  if (sqlda == NULL)
134  {
135  printf("dump_sqlda called with NULL sqlda\n");
136  return;
137  }
138 
139  for (i = 0; i < sqlda->sqld; i++)
140  {
141  if (sqlda->sqlvar[i].sqlind && *(sqlda->sqlvar[i].sqlind) == -1)
142  printf("name sqlda descriptor: '%s' value NULL'\n", sqlda->sqlvar[i].sqlname.data);
143  else
144  switch (sqlda->sqlvar[i].sqltype)
145  {
146  case ECPGt_char:
147  printf("name sqlda descriptor: '%s' value '%s'\n", sqlda->sqlvar[i].sqlname.data, sqlda->sqlvar[i].sqldata);
148  break;
149  case ECPGt_int:
150  printf("name sqlda descriptor: '%s' value %d\n", sqlda->sqlvar[i].sqlname.data, *(int *)sqlda->sqlvar[i].sqldata);
151  break;
152  case ECPGt_long:
153  printf("name sqlda descriptor: '%s' value %ld\n", sqlda->sqlvar[i].sqlname.data, *(long int *)sqlda->sqlvar[i].sqldata);
154  break;
155 #ifdef HAVE_LONG_LONG_INT
156  case ECPGt_long_long:
157  printf("name sqlda descriptor: '%s' value %lld\n", sqlda->sqlvar[i].sqlname.data, *(long long int *)sqlda->sqlvar[i].sqldata);
158  break;
159 #endif
160  case ECPGt_double:
161  printf("name sqlda descriptor: '%s' value %f\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
162  break;
163  case ECPGt_numeric:
164  {
165  char *val;
166 
167  val = PGTYPESnumeric_to_asc((numeric*)sqlda->sqlvar[i].sqldata, -1);
168  printf("name sqlda descriptor: '%s' value NUMERIC '%s'\n", sqlda->sqlvar[i].sqlname.data, val);
169  free(val);
170  break;
171  }
172  }
173  }
174 }
175 
176 int
177 main (void)
178 {
179 /* exec sql begin declare section */
180 
181 
182 
183 
184 
185 #line 67 "sqlda.pgc"
186  char * stmt1 = "SELECT * FROM t1" ;
187 
188 #line 68 "sqlda.pgc"
189  char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
190 
191 #line 69 "sqlda.pgc"
192  int rec ;
193 
194 #line 70 "sqlda.pgc"
195  int id ;
196 /* exec sql end declare section */
197 #line 71 "sqlda.pgc"
198 
199 
200  char msg[128];
201 
202  ECPGdebug(1, stderr);
203 
204  strcpy(msg, "connect");
205  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "regress1", 0);
206 #line 78 "sqlda.pgc"
207 
208 if (sqlca.sqlcode < 0) exit (1);}
209 #line 78 "sqlda.pgc"
210 
211 
212  strcpy(msg, "set");
213  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
214 #line 81 "sqlda.pgc"
215 
216 if (sqlca.sqlcode < 0) exit (1);}
217 #line 81 "sqlda.pgc"
218 
219 
220  strcpy(msg, "create");
221  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) , big bigint )", ECPGt_EOIT, ECPGt_EORT);
222 #line 91 "sqlda.pgc"
223 
224 if (sqlca.sqlcode < 0) exit (1);}
225 #line 91 "sqlda.pgc"
226 
227 
228  strcpy(msg, "insert");
229  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' , 1111111111111111111 ) , ( 2 , null , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' , 4444444444444444444 )", ECPGt_EOIT, ECPGt_EORT);
230 #line 97 "sqlda.pgc"
231 
232 if (sqlca.sqlcode < 0) exit (1);}
233 #line 97 "sqlda.pgc"
234 
235 
236  strcpy(msg, "commit");
237  { ECPGtrans(__LINE__, NULL, "commit");
238 #line 100 "sqlda.pgc"
239 
240 if (sqlca.sqlcode < 0) exit (1);}
241 #line 100 "sqlda.pgc"
242 
243 
244  /* SQLDA test for getting all records from a table */
245 
246  outp_sqlda = NULL;
247 
248  strcpy(msg, "prepare");
249  { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
250 #line 107 "sqlda.pgc"
251 
252 if (sqlca.sqlcode < 0) exit (1);}
253 #line 107 "sqlda.pgc"
254 
255 
256  strcpy(msg, "declare");
257  /* declare mycur1 cursor for $1 */
258 #line 110 "sqlda.pgc"
259 
260 
261  strcpy(msg, "open");
262  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
263  ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
264  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
265 #line 113 "sqlda.pgc"
266 
267 if (sqlca.sqlcode < 0) exit (1);}
268 #line 113 "sqlda.pgc"
269 
270 
271  /* exec sql whenever not found break ; */
272 #line 115 "sqlda.pgc"
273 
274 
275  rec = 0;
276  while (1)
277  {
278  strcpy(msg, "fetch");
279  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
280  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
281  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
282 #line 121 "sqlda.pgc"
283 
284 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
285 #line 121 "sqlda.pgc"
286 
287 if (sqlca.sqlcode < 0) exit (1);}
288 #line 121 "sqlda.pgc"
289 
290 
291  printf("FETCH RECORD %d\n", ++rec);
292  dump_sqlda(outp_sqlda);
293  }
294 
295  /* exec sql whenever not found continue ; */
296 #line 127 "sqlda.pgc"
297 
298 
299  strcpy(msg, "close");
300  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
301 #line 130 "sqlda.pgc"
302 
303 if (sqlca.sqlcode < 0) exit (1);}
304 #line 130 "sqlda.pgc"
305 
306 
307  strcpy(msg, "deallocate");
308  { ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
309 #line 133 "sqlda.pgc"
310 
311 if (sqlca.sqlcode < 0) exit (1);}
312 #line 133 "sqlda.pgc"
313 
314 
315  free(outp_sqlda);
316 
317  /* SQLDA test for getting ALL records into the sqlda list */
318 
319  outp_sqlda = NULL;
320 
321  strcpy(msg, "prepare");
322  { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
323 #line 142 "sqlda.pgc"
324 
325 if (sqlca.sqlcode < 0) exit (1);}
326 #line 142 "sqlda.pgc"
327 
328 
329  strcpy(msg, "declare");
330  /* declare mycur2 cursor for $1 */
331 #line 145 "sqlda.pgc"
332 
333 
334  strcpy(msg, "open");
335  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
336  ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
337  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
338 #line 148 "sqlda.pgc"
339 
340 if (sqlca.sqlcode < 0) exit (1);}
341 #line 148 "sqlda.pgc"
342 
343 
344  strcpy(msg, "fetch");
345  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT,
346  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
347  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
348 #line 151 "sqlda.pgc"
349 
350 if (sqlca.sqlcode < 0) exit (1);}
351 #line 151 "sqlda.pgc"
352 
353 
354  outp_sqlda1 = outp_sqlda;
355  rec = 0;
356  while (outp_sqlda1)
357  {
358  sqlda_t *ptr;
359  printf("FETCH RECORD %d\n", ++rec);
360  dump_sqlda(outp_sqlda1);
361 
362  ptr = outp_sqlda1;
363  outp_sqlda1 = outp_sqlda1->desc_next;
364  free(ptr);
365  }
366 
367  strcpy(msg, "close");
368  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
369 #line 167 "sqlda.pgc"
370 
371 if (sqlca.sqlcode < 0) exit (1);}
372 #line 167 "sqlda.pgc"
373 
374 
375  strcpy(msg, "deallocate");
376  { ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
377 #line 170 "sqlda.pgc"
378 
379 if (sqlca.sqlcode < 0) exit (1);}
380 #line 170 "sqlda.pgc"
381 
382 
383  /* SQLDA test for getting one record using an input descriptor */
384 
385  /*
386  * Input sqlda has to be built manually
387  * sqlda_t contains 1 sqlvar_t structure already.
388  */
389  inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
390  memset(inp_sqlda, 0, sizeof(sqlda_t));
391  inp_sqlda->sqln = 1;
392 
393  inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
394  inp_sqlda->sqlvar[0].sqldata = (char *)&id;
395 
396  printf("EXECUTE RECORD 4\n");
397 
398  id = 4;
399 
400  outp_sqlda = NULL;
401 
402  strcpy(msg, "prepare");
403  { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
404 #line 192 "sqlda.pgc"
405 
406 if (sqlca.sqlcode < 0) exit (1);}
407 #line 192 "sqlda.pgc"
408 
409 
410  strcpy(msg, "execute");
411  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "st_id3",
412  ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
413  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
414  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
415  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
416 #line 195 "sqlda.pgc"
417 
418 if (sqlca.sqlcode < 0) exit (1);}
419 #line 195 "sqlda.pgc"
420 
421 
422  dump_sqlda(outp_sqlda);
423 
424  strcpy(msg, "deallocate");
425  { ECPGdeallocate(__LINE__, 0, NULL, "st_id3");
426 #line 200 "sqlda.pgc"
427 
428 if (sqlca.sqlcode < 0) exit (1);}
429 #line 200 "sqlda.pgc"
430 
431 
432  free(inp_sqlda);
433  free(outp_sqlda);
434 
435  /* SQLDA test for getting one record using an input descriptor
436  * on a named connection
437  */
438 
439  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "con2", 0);
440 #line 209 "sqlda.pgc"
441 
442 if (sqlca.sqlcode < 0) exit (1);}
443 #line 209 "sqlda.pgc"
444 
445 
446  /*
447  * Input sqlda has to be built manually
448  * sqlda_t contains 1 sqlvar_t structure already.
449  */
450  inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
451  memset(inp_sqlda, 0, sizeof(sqlda_t));
452  inp_sqlda->sqln = 1;
453 
454  inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
455  inp_sqlda->sqlvar[0].sqldata = (char *)&id;
456 
457  printf("EXECUTE RECORD 4\n");
458 
459  id = 4;
460 
461  outp_sqlda = NULL;
462 
463  strcpy(msg, "prepare");
464  { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
465 #line 229 "sqlda.pgc"
466 
467 if (sqlca.sqlcode < 0) exit (1);}
468 #line 229 "sqlda.pgc"
469 
470 
471  strcpy(msg, "execute");
472  { ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_execute, "st_id4",
473  ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
474  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
475  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
476  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
477 #line 232 "sqlda.pgc"
478 
479 if (sqlca.sqlcode < 0) exit (1);}
480 #line 232 "sqlda.pgc"
481 
482 
483  dump_sqlda(outp_sqlda);
484 
485  strcpy(msg, "commit");
486  { ECPGtrans(__LINE__, "con2", "commit");
487 #line 237 "sqlda.pgc"
488 
489 if (sqlca.sqlcode < 0) exit (1);}
490 #line 237 "sqlda.pgc"
491 
492 
493  strcpy(msg, "deallocate");
494  { ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
495 #line 240 "sqlda.pgc"
496 
497 if (sqlca.sqlcode < 0) exit (1);}
498 #line 240 "sqlda.pgc"
499 
500 
501  free(inp_sqlda);
502  free(outp_sqlda);
503 
504  strcpy(msg, "disconnect");
505  { ECPGdisconnect(__LINE__, "con2");
506 #line 246 "sqlda.pgc"
507 
508 if (sqlca.sqlcode < 0) exit (1);}
509 #line 246 "sqlda.pgc"
510 
511 
512  /* End test */
513 
514  strcpy(msg, "drop");
515  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
516 #line 251 "sqlda.pgc"
517 
518 if (sqlca.sqlcode < 0) exit (1);}
519 #line 251 "sqlda.pgc"
520 
521 
522  strcpy(msg, "commit");
523  { ECPGtrans(__LINE__, NULL, "commit");
524 #line 254 "sqlda.pgc"
525 
526 if (sqlca.sqlcode < 0) exit (1);}
527 #line 254 "sqlda.pgc"
528 
529 
530  strcpy(msg, "disconnect");
531  { ECPGdisconnect(__LINE__, "CURRENT");
532 #line 257 "sqlda.pgc"
533 
534 if (sqlca.sqlcode < 0) exit (1);}
535 #line 257 "sqlda.pgc"
536 
537 
538  return 0;
539 }
decimal * PGTYPESdecimal_new(void)
Definition: numeric.c:144
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:127
struct sqlda_struct * desc_next
Definition: sqlda-native.h:39
#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:2037
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
static void dump_sqlda(sqlda_t *sqlda)
Definition: sql-sqlda.c:129
int PGTYPESnumeric_sub(numeric *, numeric *, numeric *)
Definition: numeric.c:850
char * sqldata
Definition: sqlda-native.h:28
int PGTYPESnumeric_from_long(signed long int, numeric *)
Definition: numeric.c:1405
#define malloc(a)
Definition: header.h:50
#define DECSIZE
Definition: sql-sqlda.c:62
unsigned char NumericDigit
Definition: sql-sqlda.c:64
int PGTYPESnumeric_copy(numeric *, numeric *)
Definition: numeric.c:1475
int PGTYPESnumeric_add(numeric *, numeric *, numeric *)
Definition: numeric.c:722
int PGTYPESnumeric_div(numeric *, numeric *, numeric *)
Definition: numeric.c:1138
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
char sign
Definition: informix.c:693
static char * buf
Definition: pg_test_fsync.c:67
int main(void)
Definition: sql-sqlda.c:177
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:944
int16 NumericDigit
Definition: numeric.c:100
int PGTYPESnumeric_to_decimal(numeric *, decimal *)
Definition: numeric.c:1629
void PGTYPESdecimal_free(decimal *)
Definition: numeric.c:477
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition: prepare.c:253
int PGTYPESnumeric_from_double(double, numeric *)
Definition: numeric.c:1498
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
sqlda_t * inp_sqlda
Definition: sql-sqlda.c:126
#define free(a)
Definition: header.h:65
int PGTYPESnumeric_from_int(signed int, numeric *)
Definition: numeric.c:1396
int PGTYPESnumeric_to_int(numeric *, int *)
Definition: numeric.c:1581
char * PGTYPESnumeric_to_asc(numeric *, int)
Definition: numeric.c:428
sqlda_t * outp_sqlda
Definition: sql-sqlda.c:126
int PGTYPESnumeric_mul(numeric *, numeric *, numeric *)
Definition: numeric.c:981
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition: prepare.c:306
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
short * sqlind
Definition: sqlda-native.h:29
int i
int PGTYPESnumeric_cmp(numeric *, numeric *)
Definition: numeric.c:1367
struct sqlname sqlname
Definition: sqlda-native.h:30
int PGTYPESnumeric_from_decimal(decimal *, numeric *)
Definition: numeric.c:1652
int PGTYPESnumeric_to_long(numeric *, long *)
Definition: numeric.c:1600
sqlda_t * outp_sqlda1
Definition: sql-sqlda.c:126
long val
Definition: informix.c:689
#define ECPGdebug(X, Y)
Definition: sql-sqlda.c:7
int PGTYPESnumeric_to_double(numeric *, double *)
Definition: numeric.c:1570
int digits
Definition: informix.c:691