Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc651c0e

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 parent96b8d58 commitc651c0e

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+
#defineECPGdebug(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+
#ifndefPGTYPES_NUMERIC
29+
#definePGTYPES_NUMERIC
30+
31+
#defineNUMERIC_POS0x0000
32+
#defineNUMERIC_NEG0x4000
33+
#defineNUMERIC_NAN0xC000
34+
#defineNUMERIC_MAX_PRECISION1000
35+
#defineNUMERIC_MAX_DISPLAY_SCALENUMERIC_MAX_PRECISION
36+
#defineNUMERIC_MIN_DISPLAY_SCALE0
37+
#defineNUMERIC_MIN_SIG_DIGITS16
38+
39+
#defineDECSIZE 30
40+
41+
typedefunsignedcharNumericDigit;
42+
typedefstruct
43+
{
44+
intndigits;/* number of digits in digits[] - can be 0! */
45+
intweight;/* weight of first digit */
46+
intrscale;/* result scale */
47+
intdscale;/* display scale */
48+
intsign;/* 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+
typedefstruct
54+
{
55+
intndigits;/* number of digits in digits[] - can be 0! */
56+
intweight;/* weight of first digit */
57+
intrscale;/* result scale */
58+
intdscale;/* display scale */
59+
intsign;/* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
60+
NumericDigitdigits[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+
voidPGTYPESnumeric_free(numeric*);
71+
voidPGTYPESdecimal_free(decimal*);
72+
numeric*PGTYPESnumeric_from_asc(char*,char**);
73+
char*PGTYPESnumeric_to_asc(numeric*,int);
74+
intPGTYPESnumeric_add(numeric*,numeric*,numeric*);
75+
intPGTYPESnumeric_sub(numeric*,numeric*,numeric*);
76+
intPGTYPESnumeric_mul(numeric*,numeric*,numeric*);
77+
intPGTYPESnumeric_div(numeric*,numeric*,numeric*);
78+
intPGTYPESnumeric_cmp(numeric*,numeric*);
79+
intPGTYPESnumeric_from_int(signedint,numeric*);
80+
intPGTYPESnumeric_from_long(signed longint,numeric*);
81+
intPGTYPESnumeric_copy(numeric*,numeric*);
82+
intPGTYPESnumeric_from_double(double,numeric*);
83+
intPGTYPESnumeric_to_double(numeric*,double*);
84+
intPGTYPESnumeric_to_int(numeric*,int*);
85+
intPGTYPESnumeric_to_long(numeric*,long*);
86+
intPGTYPESnumeric_to_decimal(numeric*,decimal*);
87+
intPGTYPESnumeric_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+
typedefstructmytypeMYTYPE ;
110+
111+
#line 9 "struct.h"
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
typedefstructmynulltypeMYNULLTYPE ;
122+
123+
#line 18 "struct.h"
124+
125+
126+
#line 11 "outofscope.pgc"
127+
128+
structmytype {
129+
#line 3 "struct.h"
130+
intid ;
131+
132+
#line 4 "struct.h"
133+
chart [64 ] ;
134+
135+
#line 5 "struct.h"
136+
doubled1 ;
137+
138+
#line 6 "struct.h"
139+
doubled2 ;
140+
141+
#line 7 "struct.h"
142+
charc [30 ] ;
143+
} ;structmynulltype {
144+
#line 12 "struct.h"
145+
intid ;
146+
147+
#line 13 "struct.h"
148+
intt ;
149+
150+
#line 14 "struct.h"
151+
intd1 ;
152+
153+
#line 15 "struct.h"
154+
intd2 ;
155+
156+
#line 16 "struct.h"
157+
intc ;
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+
staticvoid
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+
staticvoid
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+
staticvoid
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+
staticvoid
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+
charmsg[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)

[8]ページ先頭

©2009-2025 Movatter.jp