PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
preproc-outofscope.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 "outofscope.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <limits.h>
14 
15 
16 #line 1 "regression.h"
17 
18 
19 
20 
21 
22 
23 #line 6 "outofscope.pgc"
24 
25 
26 
27 #line 1 "pgtypes_numeric.h"
28 #ifndef PGTYPES_NUMERIC
29 #define PGTYPES_NUMERIC
30 
31 #define NUMERIC_POS 0x0000
32 #define NUMERIC_NEG 0x4000
33 #define NUMERIC_NAN 0xC000
34 #define NUMERIC_NULL 0xF000
35 #define NUMERIC_MAX_PRECISION 1000
36 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
37 #define NUMERIC_MIN_DISPLAY_SCALE 0
38 #define NUMERIC_MIN_SIG_DIGITS 16
39 
40 #define DECSIZE 30
41 
42 typedef unsigned char NumericDigit;
43 typedef struct
44 {
45  int ndigits; /* number of digits in digits[] - can be 0! */
46  int weight; /* weight of first digit */
47  int rscale; /* result scale */
48  int dscale; /* display scale */
49  int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
50  NumericDigit *buf; /* start of alloc'd space for digits[] */
51  NumericDigit *digits; /* decimal digits */
52 } numeric;
53 
54 typedef struct
55 {
56  int ndigits; /* number of digits in digits[] - can be 0! */
57  int weight; /* weight of first digit */
58  int rscale; /* result scale */
59  int dscale; /* display scale */
60  int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
61  NumericDigit digits[DECSIZE]; /* decimal digits */
62 } decimal;
63 
64 #ifdef __cplusplus
65 extern "C"
66 {
67 #endif
68 
73 numeric *PGTYPESnumeric_from_asc(char *, char **);
74 char *PGTYPESnumeric_to_asc(numeric *, int);
80 int PGTYPESnumeric_from_int(signed int, numeric *);
81 int PGTYPESnumeric_from_long(signed long int, numeric *);
83 int PGTYPESnumeric_from_double(double, numeric *);
84 int PGTYPESnumeric_to_double(numeric *, double *);
85 int PGTYPESnumeric_to_int(numeric *, int *);
86 int PGTYPESnumeric_to_long(numeric *, long *);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif /* PGTYPES_NUMERIC */
95 
96 #line 8 "outofscope.pgc"
97 
98 
99 /* exec sql begin declare section */
100 
101 #line 1 "struct.h"
102 
103 
104 
105 
106  /* dec_t */
107 
108 
109 
110  typedef struct mytype MYTYPE ;
111 
112 #line 9 "struct.h"
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123  typedef struct mynulltype MYNULLTYPE ;
124 
125 #line 19 "struct.h"
126 
127 
128 #line 11 "outofscope.pgc"
129 
130 struct mytype {
131 #line 3 "struct.h"
132  int id ;
133 
134 #line 4 "struct.h"
135  char t [ 64 ] ;
136 
137 #line 5 "struct.h"
138  double d1 ;
139 
140 #line 6 "struct.h"
141  double d2 ;
142 
143 #line 7 "struct.h"
144  char c [ 30 ] ;
145  } ; struct mynulltype {
146 #line 13 "struct.h"
147  int id ;
148 
149 #line 14 "struct.h"
150  int t ;
151 
152 #line 15 "struct.h"
153  int d1 ;
154 
155 #line 16 "struct.h"
156  int d2 ;
157 
158 #line 17 "struct.h"
159  int c ;
160  } ;/* exec sql end declare section */
161 #line 12 "outofscope.pgc"
162 
163 
164 /* exec sql whenever sqlerror stop ; */
165 #line 14 "outofscope.pgc"
166 
167 
168 /* Functions for test 1 */
169 
170 static void
171 get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
172 {
173  /* exec sql begin declare section */
174 
175 
176 
177 #line 22 "outofscope.pgc"
178  MYTYPE * myvar = malloc ( sizeof ( MYTYPE ) ) ;
179 
180 #line 23 "outofscope.pgc"
181  MYNULLTYPE * mynullvar = malloc ( sizeof ( MYNULLTYPE ) ) ;
182 /* exec sql end declare section */
183 #line 24 "outofscope.pgc"
184 
185 
186  /* Test DECLARE ... SELECT ... INTO with pointers */
187 
188  ECPGset_var( 0, ( myvar ), __LINE__);\
189  ECPGset_var( 1, ( mynullvar ), __LINE__);\
190  /* declare mycur cursor for select * from a1 */
191 #line 28 "outofscope.pgc"
192 
193 
194  if (sqlca.sqlcode != 0)
195  exit(1);
196 
197  *myvar0 = myvar;
198  *mynullvar0 = mynullvar;
199 }
200 
201 static void
203 {
204  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT,
205  ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ),
206  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ),
207  ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ),
208  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ),
209  ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ),
210  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ),
211  ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ),
212  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ),
213  ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ),
214  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
215 #line 40 "outofscope.pgc"
216 
217 if (sqlca.sqlcode < 0) exit (1);}
218 #line 40 "outofscope.pgc"
219 
220 
221  if (sqlca.sqlcode != 0)
222  exit(1);
223 }
224 
225 static void
227 {
228  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT,
229  ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ),
230  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ),
231  ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ),
232  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ),
233  ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ),
234  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ),
235  ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ),
236  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ),
237  ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ),
238  ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
239 #line 49 "outofscope.pgc"
240 
241 if (sqlca.sqlcode < 0) exit (1);}
242 #line 49 "outofscope.pgc"
243 
244 
245  if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
246  exit(1);
247 }
248 
249 static void
251 {
252  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
253 #line 58 "outofscope.pgc"
254 
255 if (sqlca.sqlcode < 0) exit (1);}
256 #line 58 "outofscope.pgc"
257 
258 
259  if (sqlca.sqlcode != 0)
260  exit(1);
261 }
262 
263 int
264 main (void)
265 {
266  MYTYPE *myvar;
267  MYNULLTYPE *mynullvar;
268 
269  char msg[128];
270 
271  ECPGdebug(1, stderr);
272 
273  strcpy(msg, "connect");
274  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
275 #line 75 "outofscope.pgc"
276 
277 if (sqlca.sqlcode < 0) exit (1);}
278 #line 75 "outofscope.pgc"
279 
280 
281  strcpy(msg, "set");
282  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
283 #line 78 "outofscope.pgc"
284 
285 if (sqlca.sqlcode < 0) exit (1);}
286 #line 78 "outofscope.pgc"
287 
288 
289  strcpy(msg, "create");
290  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table a1 ( id serial primary key , t text , d1 numeric , d2 float8 , c character ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
291 #line 81 "outofscope.pgc"
292 
293 if (sqlca.sqlcode < 0) exit (1);}
294 #line 81 "outofscope.pgc"
295 
296 
297  strcpy(msg, "insert");
298  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'a' , 1.0 , 2 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
299 #line 84 "outofscope.pgc"
300 
301 if (sqlca.sqlcode < 0) exit (1);}
302 #line 84 "outofscope.pgc"
303 
304  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , null , null , null , null )", ECPGt_EOIT, ECPGt_EORT);
305 #line 85 "outofscope.pgc"
306 
307 if (sqlca.sqlcode < 0) exit (1);}
308 #line 85 "outofscope.pgc"
309 
310  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'b' , 2.0 , 3 , 'b' )", ECPGt_EOIT, ECPGt_EORT);
311 #line 86 "outofscope.pgc"
312 
313 if (sqlca.sqlcode < 0) exit (1);}
314 #line 86 "outofscope.pgc"
315 
316 
317  strcpy(msg, "commit");
318  { ECPGtrans(__LINE__, NULL, "commit");
319 #line 89 "outofscope.pgc"
320 
321 if (sqlca.sqlcode < 0) exit (1);}
322 #line 89 "outofscope.pgc"
323 
324 
325  /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
326 
327  get_var1(&myvar, &mynullvar);
328  open_cur1();
329 
330  /* exec sql whenever not found break ; */
331 #line 96 "outofscope.pgc"
332 
333 
334  while (1)
335  {
336  memset(myvar, 0, sizeof(MYTYPE));
337  get_record1();
338  if (sqlca.sqlcode == ECPG_NOT_FOUND)
339  break;
340  printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n",
341  myvar->id, mynullvar->id ? " (NULL)" : "",
342  myvar->t, mynullvar->t ? " (NULL)" : "",
343  myvar->d1, mynullvar->d1 ? " (NULL)" : "",
344  myvar->d2, mynullvar->d2 ? " (NULL)" : "",
345  myvar->c, mynullvar->c ? " (NULL)" : "");
346  }
347 
348  close_cur1();
349 
350  free(myvar);
351  free(mynullvar);
352 
353  strcpy(msg, "drop");
354  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
355 #line 118 "outofscope.pgc"
356 
357 if (sqlca.sqlcode < 0) exit (1);}
358 #line 118 "outofscope.pgc"
359 
360 
361  strcpy(msg, "commit");
362  { ECPGtrans(__LINE__, NULL, "commit");
363 #line 121 "outofscope.pgc"
364 
365 if (sqlca.sqlcode < 0) exit (1);}
366 #line 121 "outofscope.pgc"
367 
368 
369  strcpy(msg, "disconnect");
370  { ECPGdisconnect(__LINE__, "CURRENT");
371 #line 124 "outofscope.pgc"
372 
373 if (sqlca.sqlcode < 0) exit (1);}
374 #line 124 "outofscope.pgc"
375 
376 
377  return (0);
378 }
int PGTYPESnumeric_from_long(signed long int, numeric *)
Definition: numeric.c:1405
char t[64]
void PGTYPESdecimal_free(decimal *)
Definition: numeric.c:477
int PGTYPESnumeric_to_decimal(numeric *, decimal *)
Definition: numeric.c:1629
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
int PGTYPESnumeric_sub(numeric *, numeric *, numeric *)
Definition: numeric.c:850
int PGTYPESnumeric_div(numeric *, numeric *, numeric *)
Definition: numeric.c:1138
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:127
#define ECPGdebug(X, Y)
void * ECPGget_var(int number)
Definition: misc.c:568
int PGTYPESnumeric_to_long(numeric *, long *)
Definition: numeric.c:1600
#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
static void get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
void ECPGset_var(int number, void *pointer, int lineno)
Definition: misc.c:524
#define DECSIZE
static void close_cur1(void)
int PGTYPESnumeric_mul(numeric *, numeric *, numeric *)
Definition: numeric.c:981
int PGTYPESnumeric_from_decimal(decimal *, numeric *)
Definition: numeric.c:1652
#define malloc(a)
Definition: header.h:50
int PGTYPESnumeric_copy(numeric *, numeric *)
Definition: numeric.c:1475
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
static void open_cur1(void)
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
int PGTYPESnumeric_from_int(signed int, numeric *)
Definition: numeric.c:1396
char * c
static char * buf
Definition: pg_test_fsync.c:65
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:933
int main(void)
int16 NumericDigit
Definition: numeric.c:99
int PGTYPESnumeric_to_int(numeric *, int *)
Definition: numeric.c:1581
int PGTYPESnumeric_add(numeric *, numeric *, numeric *)
Definition: numeric.c:722
char c[30]
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
decimal * PGTYPESdecimal_new(void)
Definition: numeric.c:144
#define free(a)
Definition: header.h:65
char * PGTYPESnumeric_to_asc(numeric *, int)
Definition: numeric.c:428
#define NULL
Definition: c.h:229
static void get_record1(void)
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:199
unsigned char NumericDigit
int PGTYPESnumeric_to_double(numeric *, double *)
Definition: numeric.c:1570
int PGTYPESnumeric_from_double(double, numeric *)
Definition: numeric.c:1498
int PGTYPESnumeric_cmp(numeric *, numeric *)
Definition: numeric.c:1367
int digits
Definition: informix.c:691