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