~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/test/expected/preproc-outofscope.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

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