Header And Logo

PostgreSQL
| The world's most advanced open source database.

preproc-outofscope.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* End of automatic include section */
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008 
00009 #line 1 "outofscope.pgc"
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <limits.h>
00014 
00015 
00016 #line 1 "regression.h"
00017 
00018 
00019 
00020 
00021 
00022 
00023 #line 6 "outofscope.pgc"
00024 
00025 
00026 
00027 #line 1 "pgtypes_numeric.h"
00028 #ifndef PGTYPES_NUMERIC
00029 #define PGTYPES_NUMERIC
00030 
00031 #define NUMERIC_POS                     0x0000
00032 #define NUMERIC_NEG                     0x4000
00033 #define NUMERIC_NAN                     0xC000
00034 #define NUMERIC_NULL                        0xF000
00035 #define NUMERIC_MAX_PRECISION           1000
00036 #define NUMERIC_MAX_DISPLAY_SCALE       NUMERIC_MAX_PRECISION
00037 #define NUMERIC_MIN_DISPLAY_SCALE       0
00038 #define NUMERIC_MIN_SIG_DIGITS          16
00039 
00040 #define DECSIZE 30
00041 
00042 typedef unsigned char NumericDigit;
00043 typedef struct
00044 {
00045     int         ndigits;        /* number of digits in digits[] - can be 0! */
00046     int         weight;         /* weight of first digit */
00047     int         rscale;         /* result scale */
00048     int         dscale;         /* display scale */
00049     int         sign;           /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
00050     NumericDigit *buf;          /* start of alloc'd space for digits[] */
00051     NumericDigit *digits;       /* decimal digits */
00052 } numeric;
00053 
00054 typedef struct
00055 {
00056     int         ndigits;        /* number of digits in digits[] - can be 0! */
00057     int         weight;         /* weight of first digit */
00058     int         rscale;         /* result scale */
00059     int         dscale;         /* display scale */
00060     int         sign;           /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
00061     NumericDigit digits[DECSIZE];       /* decimal digits */
00062 } decimal;
00063 
00064 #ifdef __cplusplus
00065 extern      "C"
00066 {
00067 #endif
00068 
00069 numeric    *PGTYPESnumeric_new(void);
00070 decimal    *PGTYPESdecimal_new(void);
00071 void        PGTYPESnumeric_free(numeric *);
00072 void        PGTYPESdecimal_free(decimal *);
00073 numeric    *PGTYPESnumeric_from_asc(char *, char **);
00074 char       *PGTYPESnumeric_to_asc(numeric *, int);
00075 int         PGTYPESnumeric_add(numeric *, numeric *, numeric *);
00076 int         PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
00077 int         PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
00078 int         PGTYPESnumeric_div(numeric *, numeric *, numeric *);
00079 int         PGTYPESnumeric_cmp(numeric *, numeric *);
00080 int         PGTYPESnumeric_from_int(signed int, numeric *);
00081 int         PGTYPESnumeric_from_long(signed long int, numeric *);
00082 int         PGTYPESnumeric_copy(numeric *, numeric *);
00083 int         PGTYPESnumeric_from_double(double, numeric *);
00084 int         PGTYPESnumeric_to_double(numeric *, double *);
00085 int         PGTYPESnumeric_to_int(numeric *, int *);
00086 int         PGTYPESnumeric_to_long(numeric *, long *);
00087 int         PGTYPESnumeric_to_decimal(numeric *, decimal *);
00088 int         PGTYPESnumeric_from_decimal(decimal *, numeric *);
00089 
00090 #ifdef __cplusplus
00091 }
00092 #endif
00093 
00094 #endif   /* PGTYPES_NUMERIC */
00095 
00096 #line 8 "outofscope.pgc"
00097 
00098 
00099 /* exec sql begin declare section */
00100 
00101 #line 1 "struct.h"
00102  
00103 
00104                 
00105             
00106                             /* dec_t */
00107             
00108             
00109 
00110    typedef struct mytype  MYTYPE ;
00111 
00112 #line 9 "struct.h"
00113 
00114 
00115  
00116 
00117                 
00118                 
00119                 
00120                 
00121                 
00122 
00123    typedef struct mynulltype  MYNULLTYPE ;
00124 
00125 #line 19 "struct.h"
00126 
00127 
00128 #line 11 "outofscope.pgc"
00129 
00130 struct mytype { 
00131 #line 3 "struct.h"
00132  int id ;
00133  
00134 #line 4 "struct.h"
00135  char t [ 64 ] ;
00136  
00137 #line 5 "struct.h"
00138  double d1 ;
00139  
00140 #line 6 "struct.h"
00141  double d2 ;
00142  
00143 #line 7 "struct.h"
00144  char c [ 30 ] ;
00145  } ; struct mynulltype { 
00146 #line 13 "struct.h"
00147  int id ;
00148  
00149 #line 14 "struct.h"
00150  int t ;
00151  
00152 #line 15 "struct.h"
00153  int d1 ;
00154  
00155 #line 16 "struct.h"
00156  int d2 ;
00157  
00158 #line 17 "struct.h"
00159  int c ;
00160  } ;/* exec sql end declare section */
00161 #line 12 "outofscope.pgc"
00162 
00163 
00164 /* exec sql whenever sqlerror  stop ; */
00165 #line 14 "outofscope.pgc"
00166 
00167 
00168 /* Functions for test 1 */
00169 
00170 static void
00171 get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
00172 {
00173     /* exec sql begin declare section */
00174               
00175           
00176     
00177 #line 22 "outofscope.pgc"
00178  MYTYPE * myvar = malloc ( sizeof ( MYTYPE ) ) ;
00179  
00180 #line 23 "outofscope.pgc"
00181  MYNULLTYPE * mynullvar = malloc ( sizeof ( MYNULLTYPE ) ) ;
00182 /* exec sql end declare section */
00183 #line 24 "outofscope.pgc"
00184 
00185 
00186     /* Test DECLARE ... SELECT ... INTO with pointers */
00187 
00188     ECPGset_var( 0, ( myvar ), __LINE__);\
00189  ECPGset_var( 1, ( mynullvar ), __LINE__);\
00190  /* declare mycur cursor for select * from a1 */
00191 #line 28 "outofscope.pgc"
00192 
00193 
00194     if (sqlca.sqlcode != 0)
00195         exit(1);
00196 
00197     *myvar0 = myvar;
00198     *mynullvar0 = mynullvar;
00199 }
00200 
00201 static void
00202 open_cur1(void)
00203 {
00204     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
00205     ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int), 
00206     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int), 
00207     ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char), 
00208     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof(int), 
00209     ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof(double), 
00210     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof(int), 
00211     ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof(double), 
00212     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof(int), 
00213     ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,(30)*sizeof(char), 
00214     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
00215 #line 40 "outofscope.pgc"
00216 
00217 if (sqlca.sqlcode < 0) exit (1);}
00218 #line 40 "outofscope.pgc"
00219 
00220 
00221     if (sqlca.sqlcode != 0)
00222         exit(1);
00223 }
00224 
00225 static void
00226 get_record1(void)
00227 {
00228     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
00229     ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int), 
00230     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int), 
00231     ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char), 
00232     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof(int), 
00233     ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof(double), 
00234     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof(int), 
00235     ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof(double), 
00236     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof(int), 
00237     ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,(30)*sizeof(char), 
00238     ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
00239 #line 49 "outofscope.pgc"
00240 
00241 if (sqlca.sqlcode < 0) exit (1);}
00242 #line 49 "outofscope.pgc"
00243 
00244 
00245     if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
00246         exit(1);
00247 }
00248 
00249 static void
00250 close_cur1(void)
00251 {
00252     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
00253 #line 58 "outofscope.pgc"
00254 
00255 if (sqlca.sqlcode < 0) exit (1);}
00256 #line 58 "outofscope.pgc"
00257 
00258 
00259     if (sqlca.sqlcode != 0)
00260         exit(1);
00261 }
00262 
00263 int
00264 main (void)
00265 {
00266     MYTYPE      *myvar;
00267     MYNULLTYPE  *mynullvar;
00268 
00269     char msg[128];
00270 
00271     ECPGdebug(1, stderr);
00272 
00273     strcpy(msg, "connect");
00274     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
00275 #line 75 "outofscope.pgc"
00276 
00277 if (sqlca.sqlcode < 0) exit (1);}
00278 #line 75 "outofscope.pgc"
00279 
00280 
00281     strcpy(msg, "set");
00282     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
00283 #line 78 "outofscope.pgc"
00284 
00285 if (sqlca.sqlcode < 0) exit (1);}
00286 #line 78 "outofscope.pgc"
00287 
00288 
00289     strcpy(msg, "create");
00290     { 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);
00291 #line 81 "outofscope.pgc"
00292 
00293 if (sqlca.sqlcode < 0) exit (1);}
00294 #line 81 "outofscope.pgc"
00295 
00296 
00297     strcpy(msg, "insert");
00298     { 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);
00299 #line 84 "outofscope.pgc"
00300 
00301 if (sqlca.sqlcode < 0) exit (1);}
00302 #line 84 "outofscope.pgc"
00303 
00304     { 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);
00305 #line 85 "outofscope.pgc"
00306 
00307 if (sqlca.sqlcode < 0) exit (1);}
00308 #line 85 "outofscope.pgc"
00309 
00310     { 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);
00311 #line 86 "outofscope.pgc"
00312 
00313 if (sqlca.sqlcode < 0) exit (1);}
00314 #line 86 "outofscope.pgc"
00315 
00316 
00317     strcpy(msg, "commit");
00318     { ECPGtrans(__LINE__, NULL, "commit");
00319 #line 89 "outofscope.pgc"
00320 
00321 if (sqlca.sqlcode < 0) exit (1);}
00322 #line 89 "outofscope.pgc"
00323 
00324 
00325     /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
00326 
00327     get_var1(&myvar, &mynullvar);
00328     open_cur1();
00329 
00330     /* exec sql whenever not found  break ; */
00331 #line 96 "outofscope.pgc"
00332 
00333 
00334     while (1)
00335     {
00336         memset(myvar, 0, sizeof(MYTYPE));
00337         get_record1();
00338         if (sqlca.sqlcode == ECPG_NOT_FOUND)
00339             break;
00340         printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n",
00341             myvar->id, mynullvar->id ? " (NULL)" : "",
00342             myvar->t, mynullvar->t ? " (NULL)" : "",
00343             myvar->d1, mynullvar->d1 ? " (NULL)" : "",
00344             myvar->d2, mynullvar->d2 ? " (NULL)" : "",
00345             myvar->c, mynullvar->c ? " (NULL)" : "");
00346     }
00347 
00348     close_cur1();
00349 
00350     strcpy(msg, "drop");
00351     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
00352 #line 115 "outofscope.pgc"
00353 
00354 if (sqlca.sqlcode < 0) exit (1);}
00355 #line 115 "outofscope.pgc"
00356 
00357 
00358     strcpy(msg, "commit");
00359     { ECPGtrans(__LINE__, NULL, "commit");
00360 #line 118 "outofscope.pgc"
00361 
00362 if (sqlca.sqlcode < 0) exit (1);}
00363 #line 118 "outofscope.pgc"
00364 
00365 
00366     strcpy(msg, "disconnect");
00367     { ECPGdisconnect(__LINE__, "CURRENT");
00368 #line 121 "outofscope.pgc"
00369 
00370 if (sqlca.sqlcode < 0) exit (1);}
00371 #line 121 "outofscope.pgc"
00372 
00373 
00374     return (0);
00375 }