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
44 typedef unsigned char NumericDigit;
45 typedef 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
56 typedef 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
67 extern "C"
68 {
69 #endif
70
71 numeric *PGTYPESnumeric_new(void);
72 decimal *PGTYPESdecimal_new(void);
73 void PGTYPESnumeric_free(numeric *);
74 void PGTYPESdecimal_free(decimal *);
75 numeric *PGTYPESnumeric_from_asc(char *, char **);
76 char *PGTYPESnumeric_to_asc(numeric *, int);
77 int PGTYPESnumeric_add(numeric *, numeric *, numeric *);
78 int PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
79 int PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
80 int PGTYPESnumeric_div(numeric *, numeric *, numeric *);
81 int PGTYPESnumeric_cmp(numeric *, numeric *);
82 int PGTYPESnumeric_from_int(signed int, numeric *);
83 int PGTYPESnumeric_from_long(signed long int, numeric *);
84 int PGTYPESnumeric_copy(numeric *, numeric *);
85 int PGTYPESnumeric_from_double(double, numeric *);
86 int PGTYPESnumeric_to_double(numeric *, double *);
87 int PGTYPESnumeric_to_int(numeric *, int *);
88 int PGTYPESnumeric_to_long(numeric *, long *);
89 int PGTYPESnumeric_to_decimal(numeric *, decimal *);
90 int PGTYPESnumeric_from_decimal(decimal *, numeric *);
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
132 struct 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
172 static void
get_var1(MYTYPE ** myvar0,MYNULLTYPE ** mynullvar0)173 get_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
195
196 if (sqlca.sqlcode != 0)
197 exit(1);
198
199 *myvar0 = myvar;
200 *mynullvar0 = mynullvar;
201 }
202
203 static void
open_cur1(void)204 open_cur1(void)
205 {
206 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT,
207 ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ),
208 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ),
209 ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ),
210 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ),
211 ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ),
212 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ),
213 ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ),
214 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ),
215 ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ),
216 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
217 #line 40 "outofscope.pgc"
218
219 if (sqlca.sqlcode < 0) exit (1);}
220 #line 40 "outofscope.pgc"
221
222
223 if (sqlca.sqlcode != 0)
224 exit(1);
225 }
226
227 static void
get_record1(void)228 get_record1(void)
229 {
230 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT,
231 ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ),
232 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ),
233 ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ),
234 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ),
235 ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ),
236 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ),
237 ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ),
238 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ),
239 ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ),
240 ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
241 #line 49 "outofscope.pgc"
242
243 if (sqlca.sqlcode < 0) exit (1);}
244 #line 49 "outofscope.pgc"
245
246
247 if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
248 exit(1);
249 }
250
251 static void
close_cur1(void)252 close_cur1(void)
253 {
254 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
255 #line 58 "outofscope.pgc"
256
257 if (sqlca.sqlcode < 0) exit (1);}
258 #line 58 "outofscope.pgc"
259
260
261 if (sqlca.sqlcode != 0)
262 exit(1);
263 }
264
265 int
main(void)266 main (void)
267 {
268 MYTYPE *myvar;
269 MYNULLTYPE *mynullvar;
270 int loopcount;
271 char msg[128];
272
273 ECPGdebug(1, stderr);
274
275 strcpy(msg, "connect");
276 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
277 #line 75 "outofscope.pgc"
278
279 if (sqlca.sqlcode < 0) exit (1);}
280 #line 75 "outofscope.pgc"
281
282
283 strcpy(msg, "set");
284 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
285 #line 78 "outofscope.pgc"
286
287 if (sqlca.sqlcode < 0) exit (1);}
288 #line 78 "outofscope.pgc"
289
290
291 strcpy(msg, "create");
292 { 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);
293 #line 81 "outofscope.pgc"
294
295 if (sqlca.sqlcode < 0) exit (1);}
296 #line 81 "outofscope.pgc"
297
298
299 strcpy(msg, "insert");
300 { 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);
301 #line 84 "outofscope.pgc"
302
303 if (sqlca.sqlcode < 0) exit (1);}
304 #line 84 "outofscope.pgc"
305
306 { 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);
307 #line 85 "outofscope.pgc"
308
309 if (sqlca.sqlcode < 0) exit (1);}
310 #line 85 "outofscope.pgc"
311
312 { 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);
313 #line 86 "outofscope.pgc"
314
315 if (sqlca.sqlcode < 0) exit (1);}
316 #line 86 "outofscope.pgc"
317
318
319 strcpy(msg, "commit");
320 { ECPGtrans(__LINE__, NULL, "commit");
321 #line 89 "outofscope.pgc"
322
323 if (sqlca.sqlcode < 0) exit (1);}
324 #line 89 "outofscope.pgc"
325
326
327 /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
328
329 get_var1(&myvar, &mynullvar);
330 open_cur1();
331
332 /* exec sql whenever not found break ; */
333 #line 96 "outofscope.pgc"
334
335
336 for (loopcount = 0; loopcount < 100; loopcount++)
337 {
338 memset(myvar, 0, sizeof(MYTYPE));
339 get_record1();
340 if (sqlca.sqlcode == ECPG_NOT_FOUND)
341 break;
342 printf("id=%d%s t='%s'%s d1=%f%s d2=%f%s c = '%s'%s\n",
343 myvar->id, mynullvar->id ? " (NULL)" : "",
344 myvar->t, mynullvar->t ? " (NULL)" : "",
345 myvar->d1, mynullvar->d1 ? " (NULL)" : "",
346 myvar->d2, mynullvar->d2 ? " (NULL)" : "",
347 myvar->c, mynullvar->c ? " (NULL)" : "");
348 }
349
350 close_cur1();
351
352 free(myvar);
353 free(mynullvar);
354
355 strcpy(msg, "drop");
356 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
357 #line 118 "outofscope.pgc"
358
359 if (sqlca.sqlcode < 0) exit (1);}
360 #line 118 "outofscope.pgc"
361
362
363 strcpy(msg, "commit");
364 { ECPGtrans(__LINE__, NULL, "commit");
365 #line 121 "outofscope.pgc"
366
367 if (sqlca.sqlcode < 0) exit (1);}
368 #line 121 "outofscope.pgc"
369
370
371 strcpy(msg, "disconnect");
372 { ECPGdisconnect(__LINE__, "CURRENT");
373 #line 124 "outofscope.pgc"
374
375 if (sqlca.sqlcode < 0) exit (1);}
376 #line 124 "outofscope.pgc"
377
378
379 return (0);
380 }
381