PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 
14 
15 #line 1 "regression.h"
16 
17 
18 
19 
20 
21 
22 #line 5 "sqlda.pgc"
23 
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_double:
153  printf("name sqlda descriptor: '%s' value %lf\n", sqlda->sqlvar[i].sqlname.data, *(double *)sqlda->sqlvar[i].sqldata);
154  break;
155  case ECPGt_numeric:
156  {
157  char *val;
158 
159  val = PGTYPESnumeric_to_asc((numeric*)sqlda->sqlvar[i].sqldata, -1);
160  printf("name sqlda descriptor: '%s' value NUMERIC '%s'\n", sqlda->sqlvar[i].sqlname.data, val);
161  free(val);
162  break;
163  }
164  }
165  }
166 }
167 
168 int
169 main (void)
170 {
171 /* exec sql begin declare section */
172 
173 
174 
175 
176 
177 #line 59 "sqlda.pgc"
178  char * stmt1 = "SELECT * FROM t1" ;
179 
180 #line 60 "sqlda.pgc"
181  char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;
182 
183 #line 61 "sqlda.pgc"
184  int rec ;
185 
186 #line 62 "sqlda.pgc"
187  int id ;
188 /* exec sql end declare section */
189 #line 63 "sqlda.pgc"
190 
191 
192  char msg[128];
193 
194  ECPGdebug(1, stderr);
195 
196  strcpy(msg, "connect");
197  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "regress1", 0);
198 #line 70 "sqlda.pgc"
199 
200 if (sqlca.sqlcode < 0) exit (1);}
201 #line 70 "sqlda.pgc"
202 
203 
204  strcpy(msg, "set");
205  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
206 #line 73 "sqlda.pgc"
207 
208 if (sqlca.sqlcode < 0) exit (1);}
209 #line 73 "sqlda.pgc"
210 
211 
212  strcpy(msg, "create");
213  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) )", 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, "insert");
221  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' ) , ( 2 , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' )", ECPGt_EOIT, ECPGt_EORT);
222 #line 87 "sqlda.pgc"
223 
224 if (sqlca.sqlcode < 0) exit (1);}
225 #line 87 "sqlda.pgc"
226 
227 
228  strcpy(msg, "commit");
229  { ECPGtrans(__LINE__, NULL, "commit");
230 #line 90 "sqlda.pgc"
231 
232 if (sqlca.sqlcode < 0) exit (1);}
233 #line 90 "sqlda.pgc"
234 
235 
236  /* SQLDA test for getting all records from a table */
237 
238  outp_sqlda = NULL;
239 
240  strcpy(msg, "prepare");
241  { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);
242 #line 97 "sqlda.pgc"
243 
244 if (sqlca.sqlcode < 0) exit (1);}
245 #line 97 "sqlda.pgc"
246 
247 
248  strcpy(msg, "declare");
249  /* declare mycur1 cursor for $1 */
250 #line 100 "sqlda.pgc"
251 
252 
253  strcpy(msg, "open");
254  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",
255  ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
256  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
257 #line 103 "sqlda.pgc"
258 
259 if (sqlca.sqlcode < 0) exit (1);}
260 #line 103 "sqlda.pgc"
261 
262 
263  /* exec sql whenever not found break ; */
264 #line 105 "sqlda.pgc"
265 
266 
267  rec = 0;
268  while (1)
269  {
270  strcpy(msg, "fetch");
271  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT,
272  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
273  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
274 #line 111 "sqlda.pgc"
275 
276 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
277 #line 111 "sqlda.pgc"
278 
279 if (sqlca.sqlcode < 0) exit (1);}
280 #line 111 "sqlda.pgc"
281 
282 
283  printf("FETCH RECORD %d\n", ++rec);
284  dump_sqlda(outp_sqlda);
285  }
286 
287  /* exec sql whenever not found continue ; */
288 #line 117 "sqlda.pgc"
289 
290 
291  strcpy(msg, "close");
292  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
293 #line 120 "sqlda.pgc"
294 
295 if (sqlca.sqlcode < 0) exit (1);}
296 #line 120 "sqlda.pgc"
297 
298 
299  strcpy(msg, "deallocate");
300  { ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
301 #line 123 "sqlda.pgc"
302 
303 if (sqlca.sqlcode < 0) exit (1);}
304 #line 123 "sqlda.pgc"
305 
306 
307  free(outp_sqlda);
308 
309  /* SQLDA test for getting ALL records into the sqlda list */
310 
311  outp_sqlda = NULL;
312 
313  strcpy(msg, "prepare");
314  { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);
315 #line 132 "sqlda.pgc"
316 
317 if (sqlca.sqlcode < 0) exit (1);}
318 #line 132 "sqlda.pgc"
319 
320 
321  strcpy(msg, "declare");
322  /* declare mycur2 cursor for $1 */
323 #line 135 "sqlda.pgc"
324 
325 
326  strcpy(msg, "open");
327  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",
328  ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
329  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
330 #line 138 "sqlda.pgc"
331 
332 if (sqlca.sqlcode < 0) exit (1);}
333 #line 138 "sqlda.pgc"
334 
335 
336  strcpy(msg, "fetch");
337  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT,
338  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
339  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
340 #line 141 "sqlda.pgc"
341 
342 if (sqlca.sqlcode < 0) exit (1);}
343 #line 141 "sqlda.pgc"
344 
345 
346  outp_sqlda1 = outp_sqlda;
347  rec = 0;
348  while (outp_sqlda1)
349  {
350  sqlda_t *ptr;
351  printf("FETCH RECORD %d\n", ++rec);
352  dump_sqlda(outp_sqlda1);
353 
354  ptr = outp_sqlda1;
355  outp_sqlda1 = outp_sqlda1->desc_next;
356  free(ptr);
357  }
358 
359  strcpy(msg, "close");
360  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
361 #line 157 "sqlda.pgc"
362 
363 if (sqlca.sqlcode < 0) exit (1);}
364 #line 157 "sqlda.pgc"
365 
366 
367  strcpy(msg, "deallocate");
368  { ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
369 #line 160 "sqlda.pgc"
370 
371 if (sqlca.sqlcode < 0) exit (1);}
372 #line 160 "sqlda.pgc"
373 
374 
375  /* SQLDA test for getting one record using an input descriptor */
376 
377  /*
378  * Input sqlda has to be built manually
379  * sqlda_t contains 1 sqlvar_t structure already.
380  */
381  inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
382  memset(inp_sqlda, 0, sizeof(sqlda_t));
383  inp_sqlda->sqln = 1;
384 
385  inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
386  inp_sqlda->sqlvar[0].sqldata = (char *)&id;
387 
388  printf("EXECUTE RECORD 4\n");
389 
390  id = 4;
391 
392  outp_sqlda = NULL;
393 
394  strcpy(msg, "prepare");
395  { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);
396 #line 182 "sqlda.pgc"
397 
398 if (sqlca.sqlcode < 0) exit (1);}
399 #line 182 "sqlda.pgc"
400 
401 
402  strcpy(msg, "execute");
403  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "st_id3",
404  ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
405  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
406  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
407  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
408 #line 185 "sqlda.pgc"
409 
410 if (sqlca.sqlcode < 0) exit (1);}
411 #line 185 "sqlda.pgc"
412 
413 
414  dump_sqlda(outp_sqlda);
415 
416  strcpy(msg, "deallocate");
417  { ECPGdeallocate(__LINE__, 0, NULL, "st_id3");
418 #line 190 "sqlda.pgc"
419 
420 if (sqlca.sqlcode < 0) exit (1);}
421 #line 190 "sqlda.pgc"
422 
423 
424  free(inp_sqlda);
425  free(outp_sqlda);
426 
427  /* SQLDA test for getting one record using an input descriptor
428  * on a named connection
429  */
430 
431  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "con2", 0);
432 #line 199 "sqlda.pgc"
433 
434 if (sqlca.sqlcode < 0) exit (1);}
435 #line 199 "sqlda.pgc"
436 
437 
438  /*
439  * Input sqlda has to be built manually
440  * sqlda_t contains 1 sqlvar_t structure already.
441  */
442  inp_sqlda = (sqlda_t *)malloc(sizeof(sqlda_t));
443  memset(inp_sqlda, 0, sizeof(sqlda_t));
444  inp_sqlda->sqln = 1;
445 
446  inp_sqlda->sqlvar[0].sqltype = ECPGt_int;
447  inp_sqlda->sqlvar[0].sqldata = (char *)&id;
448 
449  printf("EXECUTE RECORD 4\n");
450 
451  id = 4;
452 
453  outp_sqlda = NULL;
454 
455  strcpy(msg, "prepare");
456  { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);
457 #line 219 "sqlda.pgc"
458 
459 if (sqlca.sqlcode < 0) exit (1);}
460 #line 219 "sqlda.pgc"
461 
462 
463  strcpy(msg, "execute");
464  { ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_execute, "st_id4",
465  ECPGt_sqlda, &inp_sqlda, 0L, 0L, 0L,
466  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
467  ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L,
468  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
469 #line 222 "sqlda.pgc"
470 
471 if (sqlca.sqlcode < 0) exit (1);}
472 #line 222 "sqlda.pgc"
473 
474 
475  dump_sqlda(outp_sqlda);
476 
477  strcpy(msg, "commit");
478  { ECPGtrans(__LINE__, "con2", "commit");
479 #line 227 "sqlda.pgc"
480 
481 if (sqlca.sqlcode < 0) exit (1);}
482 #line 227 "sqlda.pgc"
483 
484 
485  strcpy(msg, "deallocate");
486  { ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
487 #line 230 "sqlda.pgc"
488 
489 if (sqlca.sqlcode < 0) exit (1);}
490 #line 230 "sqlda.pgc"
491 
492 
493  free(inp_sqlda);
494  free(outp_sqlda);
495 
496  strcpy(msg, "disconnect");
497  { ECPGdisconnect(__LINE__, "con2");
498 #line 236 "sqlda.pgc"
499 
500 if (sqlca.sqlcode < 0) exit (1);}
501 #line 236 "sqlda.pgc"
502 
503 
504  /* End test */
505 
506  strcpy(msg, "drop");
507  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
508 #line 241 "sqlda.pgc"
509 
510 if (sqlca.sqlcode < 0) exit (1);}
511 #line 241 "sqlda.pgc"
512 
513 
514  strcpy(msg, "commit");
515  { ECPGtrans(__LINE__, NULL, "commit");
516 #line 244 "sqlda.pgc"
517 
518 if (sqlca.sqlcode < 0) exit (1);}
519 #line 244 "sqlda.pgc"
520 
521 
522  strcpy(msg, "disconnect");
523  { ECPGdisconnect(__LINE__, "CURRENT");
524 #line 247 "sqlda.pgc"
525 
526 if (sqlca.sqlcode < 0) exit (1);}
527 #line 247 "sqlda.pgc"
528 
529 
530  return (0);
531 }
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:2030
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:66
int main(void)
Definition: sql-sqlda.c:169
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:933
int16 NumericDigit
Definition: numeric.c:99
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
#define NULL
Definition: c.h:229
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