Skip to content

Commit c651c0e

Browse files
author
Michael Meskes
committed
Added test case that was part of Zoltan's patch but apparently wasn't part of my commit.
1 parent 96b8d58 commit c651c0e

File tree

5 files changed

+662
-0
lines changed

5 files changed

+662
-0
lines changed
Lines changed: 379 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
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_MAX_PRECISION 1000
35+
#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
36+
#define NUMERIC_MIN_DISPLAY_SCALE 0
37+
#define NUMERIC_MIN_SIG_DIGITS 16
38+
39+
#define DECSIZE 30
40+
41+
typedef unsigned char NumericDigit;
42+
typedef struct
43+
{
44+
int ndigits; /* number of digits in digits[] - can be 0! */
45+
int weight; /* weight of first digit */
46+
int rscale; /* result scale */
47+
int dscale; /* display scale */
48+
int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
49+
NumericDigit *buf; /* start of alloc'd space for digits[] */
50+
NumericDigit *digits; /* decimal digits */
51+
} numeric;
52+
53+
typedef struct
54+
{
55+
int ndigits; /* number of digits in digits[] - can be 0! */
56+
int weight; /* weight of first digit */
57+
int rscale; /* result scale */
58+
int dscale; /* display scale */
59+
int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
60+
NumericDigit digits[DECSIZE]; /* decimal digits */
61+
} decimal;
62+
63+
#ifdef __cplusplus
64+
extern "C"
65+
{
66+
#endif
67+
68+
numeric *PGTYPESnumeric_new(void);
69+
decimal *PGTYPESdecimal_new(void);
70+
void PGTYPESnumeric_free(numeric *);
71+
void PGTYPESdecimal_free(decimal *);
72+
numeric *PGTYPESnumeric_from_asc(char *, char **);
73+
char *PGTYPESnumeric_to_asc(numeric *, int);
74+
int PGTYPESnumeric_add(numeric *, numeric *, numeric *);
75+
int PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
76+
int PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
77+
int PGTYPESnumeric_div(numeric *, numeric *, numeric *);
78+
int PGTYPESnumeric_cmp(numeric *, numeric *);
79+
int PGTYPESnumeric_from_int(signed int, numeric *);
80+
int PGTYPESnumeric_from_long(signed long int, numeric *);
81+
int PGTYPESnumeric_copy(numeric *, numeric *);
82+
int PGTYPESnumeric_from_double(double, numeric *);
83+
int PGTYPESnumeric_to_double(numeric *, double *);
84+
int PGTYPESnumeric_to_int(numeric *, int *);
85+
int PGTYPESnumeric_to_long(numeric *, long *);
86+
int PGTYPESnumeric_to_decimal(numeric *, decimal *);
87+
int PGTYPESnumeric_from_decimal(decimal *, numeric *);
88+
89+
#ifdef __cplusplus
90+
}
91+
#endif
92+
93+
#endif /* PGTYPES_NUMERIC */
94+
95+
#line 8 "outofscope.pgc"
96+
97+
98+
/* exec sql begin declare section */
99+
100+
#line 1 "struct.h"
101+
102+
103+
104+
105+
/* dec_t */
106+
107+
108+
109+
typedef struct mytype MYTYPE ;
110+
111+
#line 9 "struct.h"
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
typedef struct mynulltype MYNULLTYPE ;
122+
123+
#line 18 "struct.h"
124+
125+
126+
#line 11 "outofscope.pgc"
127+
128+
struct mytype {
129+
#line 3 "struct.h"
130+
int id ;
131+
132+
#line 4 "struct.h"
133+
char t [ 64 ] ;
134+
135+
#line 5 "struct.h"
136+
double d1 ;
137+
138+
#line 6 "struct.h"
139+
double d2 ;
140+
141+
#line 7 "struct.h"
142+
char c [ 30 ] ;
143+
} ; struct mynulltype {
144+
#line 12 "struct.h"
145+
int id ;
146+
147+
#line 13 "struct.h"
148+
int t ;
149+
150+
#line 14 "struct.h"
151+
int d1 ;
152+
153+
#line 15 "struct.h"
154+
int d2 ;
155+
156+
#line 16 "struct.h"
157+
int c ;
158+
} ;/* exec sql end declare section */
159+
#line 12 "outofscope.pgc"
160+
161+
162+
/* exec sql whenever sqlerror stop ; */
163+
#line 14 "outofscope.pgc"
164+
165+
166+
/* Functions for test 1 */
167+
168+
static void
169+
get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
170+
{
171+
/* exec sql begin declare section */
172+
173+
174+
175+
#line 22 "outofscope.pgc"
176+
MYTYPE * myvar = malloc ( sizeof ( MYTYPE ) ) ;
177+
178+
#line 23 "outofscope.pgc"
179+
MYNULLTYPE * mynullvar = malloc ( sizeof ( MYNULLTYPE ) ) ;
180+
/* exec sql end declare section */
181+
#line 24 "outofscope.pgc"
182+
183+
184+
/* Test DECLARE ... SELECT ... INTO with pointers */
185+
186+
ECPGset_var( 0, ( myvar ), __LINE__);\
187+
ECPGset_var( 1, ( mynullvar ), __LINE__);\
188+
/* declare mycur cursor for select * from a1 */
189+
#line 28 "outofscope.pgc"
190+
191+
192+
if (sqlca.sqlcode != 0)
193+
exit(1);
194+
195+
*myvar0 = myvar;
196+
*mynullvar0 = mynullvar;
197+
}
198+
199+
static void
200+
open_cur1(void)
201+
{
202+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT,
203+
ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0))).id),(long)1,(long)1,sizeof(int),
204+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).id),(long)1,(long)1,sizeof(int),
205+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0))).t),(long)64,(long)1,(64)*sizeof(char),
206+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).t),(long)1,(long)1,sizeof(int),
207+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0))).d1),(long)1,(long)1,sizeof(double),
208+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).d1),(long)1,(long)1,sizeof(int),
209+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0))).d2),(long)1,(long)1,sizeof(double),
210+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).d2),(long)1,(long)1,sizeof(int),
211+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0))).c),(long)30,(long)1,(30)*sizeof(char),
212+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
213+
#line 40 "outofscope.pgc"
214+
215+
if (sqlca.sqlcode < 0) exit (1);}
216+
#line 40 "outofscope.pgc"
217+
218+
219+
if (sqlca.sqlcode != 0)
220+
exit(1);
221+
}
222+
223+
static void
224+
get_record1(void)
225+
{
226+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT,
227+
ECPGt_int,&((*( MYTYPE *)(ECPGget_var( 0))).id),(long)1,(long)1,sizeof(int),
228+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).id),(long)1,(long)1,sizeof(int),
229+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0))).t),(long)64,(long)1,(64)*sizeof(char),
230+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).t),(long)1,(long)1,sizeof(int),
231+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0))).d1),(long)1,(long)1,sizeof(double),
232+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).d1),(long)1,(long)1,sizeof(int),
233+
ECPGt_double,&((*( MYTYPE *)(ECPGget_var( 0))).d2),(long)1,(long)1,sizeof(double),
234+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).d2),(long)1,(long)1,sizeof(int),
235+
ECPGt_char,&((*( MYTYPE *)(ECPGget_var( 0))).c),(long)30,(long)1,(30)*sizeof(char),
236+
ECPGt_int,&((*( MYNULLTYPE *)(ECPGget_var( 1))).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
237+
#line 49 "outofscope.pgc"
238+
239+
if (sqlca.sqlcode < 0) exit (1);}
240+
#line 49 "outofscope.pgc"
241+
242+
243+
if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
244+
exit(1);
245+
}
246+
247+
static void
248+
close_cur1(void)
249+
{
250+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
251+
#line 58 "outofscope.pgc"
252+
253+
if (sqlca.sqlcode < 0) exit (1);}
254+
#line 58 "outofscope.pgc"
255+
256+
257+
if (sqlca.sqlcode != 0)
258+
exit(1);
259+
}
260+
261+
int
262+
main (void)
263+
{
264+
MYTYPE *myvar;
265+
MYNULLTYPE *mynullvar;
266+
267+
char msg[128];
268+
269+
ECPGdebug(1, stderr);
270+
271+
strcpy(msg, "connect");
272+
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0);
273+
#line 75 "outofscope.pgc"
274+
275+
if (sqlca.sqlcode < 0) exit (1);}
276+
#line 75 "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 78 "outofscope.pgc"
282+
283+
if (sqlca.sqlcode < 0) exit (1);}
284+
#line 78 "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 81 "outofscope.pgc"
290+
291+
if (sqlca.sqlcode < 0) exit (1);}
292+
#line 81 "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 84 "outofscope.pgc"
298+
299+
if (sqlca.sqlcode < 0) exit (1);}
300+
#line 84 "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 85 "outofscope.pgc"
304+
305+
if (sqlca.sqlcode < 0) exit (1);}
306+
#line 85 "outofscope.pgc"
307+
308+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , '\"a\"' , - 1.0 , 'nan' :: float8 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
309+
#line 86 "outofscope.pgc"
310+
311+
if (sqlca.sqlcode < 0) exit (1);}
312+
#line 86 "outofscope.pgc"
313+
314+
{ 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);
315+
#line 87 "outofscope.pgc"
316+
317+
if (sqlca.sqlcode < 0) exit (1);}
318+
#line 87 "outofscope.pgc"
319+
320+
321+
strcpy(msg, "commit");
322+
{ ECPGtrans(__LINE__, NULL, "commit");
323+
#line 90 "outofscope.pgc"
324+
325+
if (sqlca.sqlcode < 0) exit (1);}
326+
#line 90 "outofscope.pgc"
327+
328+
329+
/* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
330+
331+
get_var1(&myvar, &mynullvar);
332+
open_cur1();
333+
334+
/* exec sql whenever not found break ; */
335+
#line 97 "outofscope.pgc"
336+
337+
338+
while (1)
339+
{
340+
memset(myvar, 0, sizeof(MYTYPE));
341+
get_record1();
342+
if (sqlca.sqlcode == ECPG_NOT_FOUND)
343+
break;
344+
printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n",
345+
myvar->id, mynullvar->id ? " (NULL)" : "",
346+
myvar->t, mynullvar->t ? " (NULL)" : "",
347+
myvar->d1, mynullvar->d1 ? " (NULL)" : "",
348+
myvar->d2, mynullvar->d2 ? " (NULL)" : "",
349+
myvar->c, mynullvar->c ? " (NULL)" : "");
350+
}
351+
352+
close_cur1();
353+
354+
strcpy(msg, "drop");
355+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
356+
#line 116 "outofscope.pgc"
357+
358+
if (sqlca.sqlcode < 0) exit (1);}
359+
#line 116 "outofscope.pgc"
360+
361+
362+
strcpy(msg, "commit");
363+
{ ECPGtrans(__LINE__, NULL, "commit");
364+
#line 119 "outofscope.pgc"
365+
366+
if (sqlca.sqlcode < 0) exit (1);}
367+
#line 119 "outofscope.pgc"
368+
369+
370+
strcpy(msg, "disconnect");
371+
{ ECPGdisconnect(__LINE__, "CURRENT");
372+
#line 122 "outofscope.pgc"
373+
374+
if (sqlca.sqlcode < 0) exit (1);}
375+
#line 122 "outofscope.pgc"
376+
377+
378+
return (0);
379+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy