Harmonize parameter names in ecpg code.
[pgsql.git] / src / interfaces / ecpg / test / expected / preproc-outofscope.c
bloba040a69014d0a53623a2c972ffce4f6f48ef65a6
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))
9 #line 1 "outofscope.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <limits.h>
16 #line 1 "regression.h"
23 #line 6 "outofscope.pgc"
27 #line 1 "pgtypes_numeric.h"
28 #ifndef PGTYPES_NUMERIC
29 #define PGTYPES_NUMERIC
31 #include <pgtypes.h>
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
42 #define DECSIZE 30
44 typedef unsigned char NumericDigit;
45 typedef struct
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;
56 typedef struct
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;
66 #ifdef __cplusplus
67 extern "C"
69 #endif
71 numeric *PGTYPESnumeric_new(void);
72 decimal *PGTYPESdecimal_new(void);
73 void PGTYPESnumeric_free(numeric *var);
74 void PGTYPESdecimal_free(decimal *var);
75 numeric *PGTYPESnumeric_from_asc(char *str, char **endptr);
76 char *PGTYPESnumeric_to_asc(numeric *num, int dscale);
77 int PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result);
78 int PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result);
79 int PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result);
80 int PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result);
81 int PGTYPESnumeric_cmp(numeric *var1, numeric *var2);
82 int PGTYPESnumeric_from_int(signed int int_val, numeric *var);
83 int PGTYPESnumeric_from_long(signed long int long_val, numeric *var);
84 int PGTYPESnumeric_copy(numeric *src, numeric *dst);
85 int PGTYPESnumeric_from_double(double d, numeric *dst);
86 int PGTYPESnumeric_to_double(numeric *nv, double *dp);
87 int PGTYPESnumeric_to_int(numeric *nv, int *ip);
88 int PGTYPESnumeric_to_long(numeric *nv, long *lp);
89 int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst);
90 int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst);
92 #ifdef __cplusplus
94 #endif
96 #endif /* PGTYPES_NUMERIC */
98 #line 8 "outofscope.pgc"
101 /* exec sql begin declare section */
103 #line 1 "struct.h"
108 /* dec_t */
112 typedef struct mytype MYTYPE ;
114 #line 9 "struct.h"
125 typedef struct mynulltype MYNULLTYPE ;
127 #line 19 "struct.h"
130 #line 11 "outofscope.pgc"
132 struct mytype {
133 #line 3 "struct.h"
134 int id ;
136 #line 4 "struct.h"
137 char t [ 64 ] ;
139 #line 5 "struct.h"
140 double d1 ;
142 #line 6 "struct.h"
143 double d2 ;
145 #line 7 "struct.h"
146 char c [ 30 ] ;
147 } ; struct mynulltype {
148 #line 13 "struct.h"
149 int id ;
151 #line 14 "struct.h"
152 int t ;
154 #line 15 "struct.h"
155 int d1 ;
157 #line 16 "struct.h"
158 int d2 ;
160 #line 17 "struct.h"
161 int c ;
162 } ;/* exec sql end declare section */
163 #line 12 "outofscope.pgc"
166 /* exec sql whenever sqlerror stop ; */
167 #line 14 "outofscope.pgc"
170 /* Functions for test 1 */
172 static void
173 get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
175 /* exec sql begin declare section */
179 #line 22 "outofscope.pgc"
180 MYTYPE * myvar = malloc ( sizeof ( MYTYPE ) ) ;
182 #line 23 "outofscope.pgc"
183 MYNULLTYPE * mynullvar = malloc ( sizeof ( MYNULLTYPE ) ) ;
184 /* exec sql end declare section */
185 #line 24 "outofscope.pgc"
188 /* Test DECLARE ... SELECT ... INTO with pointers */
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"
195 if (sqlca.sqlcode < 0) exit (1);
196 #line 28 "outofscope.pgc"
198 #line 28 "outofscope.pgc"
201 if (sqlca.sqlcode != 0)
202 exit(1);
204 *myvar0 = myvar;
205 *mynullvar0 = mynullvar;
208 static void
209 open_cur1(void)
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"
224 if (sqlca.sqlcode < 0) exit (1);}
225 #line 40 "outofscope.pgc"
229 static void
230 get_record1(void)
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"
245 if (sqlca.sqlcode < 0) exit (1);}
246 #line 46 "outofscope.pgc"
250 static void
251 close_cur1(void)
253 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
254 #line 52 "outofscope.pgc"
256 if (sqlca.sqlcode < 0) exit (1);}
257 #line 52 "outofscope.pgc"
262 main (void)
264 MYTYPE *myvar;
265 MYNULLTYPE *mynullvar;
266 int loopcount;
267 char msg[128];
269 ECPGdebug(1, stderr);
271 strcpy(msg, "connect");
272 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
273 #line 66 "outofscope.pgc"
275 if (sqlca.sqlcode < 0) exit (1);}
276 #line 66 "outofscope.pgc"
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"
283 if (sqlca.sqlcode < 0) exit (1);}
284 #line 69 "outofscope.pgc"
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"
291 if (sqlca.sqlcode < 0) exit (1);}
292 #line 72 "outofscope.pgc"
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"
299 if (sqlca.sqlcode < 0) exit (1);}
300 #line 75 "outofscope.pgc"
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"
305 if (sqlca.sqlcode < 0) exit (1);}
306 #line 76 "outofscope.pgc"
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"
311 if (sqlca.sqlcode < 0) exit (1);}
312 #line 77 "outofscope.pgc"
315 strcpy(msg, "commit");
316 { ECPGtrans(__LINE__, NULL, "commit");
317 #line 80 "outofscope.pgc"
319 if (sqlca.sqlcode < 0) exit (1);}
320 #line 80 "outofscope.pgc"
323 /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
325 get_var1(&myvar, &mynullvar);
326 open_cur1();
328 for (loopcount = 0; loopcount < 100; loopcount++)
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)" : "");
342 close_cur1();
344 free(myvar);
345 free(mynullvar);
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"
351 if (sqlca.sqlcode < 0) exit (1);}
352 #line 107 "outofscope.pgc"
355 strcpy(msg, "commit");
356 { ECPGtrans(__LINE__, NULL, "commit");
357 #line 110 "outofscope.pgc"
359 if (sqlca.sqlcode < 0) exit (1);}
360 #line 110 "outofscope.pgc"
363 strcpy(msg, "disconnect");
364 { ECPGdisconnect(__LINE__, "CURRENT");
365 #line 113 "outofscope.pgc"
367 if (sqlca.sqlcode < 0) exit (1);}
368 #line 113 "outofscope.pgc"
371 return 0;