Added test case that was part of Zoltan's patch but apparently wasn't part of my...
authorMichael Meskes <meskes@postgresql.org>
Tue, 26 Jan 2010 10:31:14 +0000 (10:31 +0000)
committerMichael Meskes <meskes@postgresql.org>
Tue, 26 Jan 2010 10:31:14 +0000 (10:31 +0000)
src/interfaces/ecpg/test/expected/preproc-outofscope.c [new file with mode: 0644]
src/interfaces/ecpg/test/expected/preproc-outofscope.stderr [new file with mode: 0644]
src/interfaces/ecpg/test/expected/preproc-outofscope.stdout [new file with mode: 0644]
src/interfaces/ecpg/test/preproc/outofscope.pgc [new file with mode: 0644]
src/interfaces/ecpg/test/preproc/struct.h [new file with mode: 0644]

diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.c b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
new file mode 100644 (file)
index 0000000..de31c65
--- /dev/null
@@ -0,0 +1,379 @@
+/* Processed by ecpg (regression mode) */
+/* These include files are added by the preprocessor */
+#include <ecpglib.h>
+#include <ecpgerrno.h>
+#include <sqlca.h>
+/* End of automatic include section */
+#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
+
+#line 1 "outofscope.pgc"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+
+#line 1 "regression.h"
+
+
+
+
+
+
+#line 6 "outofscope.pgc"
+
+
+
+#line 1 "pgtypes_numeric.h"
+#ifndef PGTYPES_NUMERIC
+#define PGTYPES_NUMERIC
+
+#define NUMERIC_POS                        0x0000
+#define NUMERIC_NEG                        0x4000
+#define NUMERIC_NAN                        0xC000
+#define NUMERIC_MAX_PRECISION          1000
+#define NUMERIC_MAX_DISPLAY_SCALE      NUMERIC_MAX_PRECISION
+#define NUMERIC_MIN_DISPLAY_SCALE      0
+#define NUMERIC_MIN_SIG_DIGITS         16
+
+#define DECSIZE 30
+
+typedef unsigned char NumericDigit;
+typedef struct
+{
+   int         ndigits;        /* number of digits in digits[] - can be 0! */
+   int         weight;         /* weight of first digit */
+   int         rscale;         /* result scale */
+   int         dscale;         /* display scale */
+   int         sign;           /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
+   NumericDigit *buf;          /* start of alloc'd space for digits[] */
+   NumericDigit *digits;       /* decimal digits */
+} numeric;
+
+typedef struct
+{
+   int         ndigits;        /* number of digits in digits[] - can be 0! */
+   int         weight;         /* weight of first digit */
+   int         rscale;         /* result scale */
+   int         dscale;         /* display scale */
+   int         sign;           /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
+   NumericDigit digits[DECSIZE];       /* decimal digits */
+} decimal;
+
+#ifdef __cplusplus
+extern     "C"
+{
+#endif
+
+numeric    *PGTYPESnumeric_new(void);
+decimal    *PGTYPESdecimal_new(void);
+void       PGTYPESnumeric_free(numeric *);
+void       PGTYPESdecimal_free(decimal *);
+numeric    *PGTYPESnumeric_from_asc(char *, char **);
+char      *PGTYPESnumeric_to_asc(numeric *, int);
+int            PGTYPESnumeric_add(numeric *, numeric *, numeric *);
+int            PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
+int            PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
+int            PGTYPESnumeric_div(numeric *, numeric *, numeric *);
+int            PGTYPESnumeric_cmp(numeric *, numeric *);
+int            PGTYPESnumeric_from_int(signed int, numeric *);
+int            PGTYPESnumeric_from_long(signed long int, numeric *);
+int            PGTYPESnumeric_copy(numeric *, numeric *);
+int            PGTYPESnumeric_from_double(double, numeric *);
+int            PGTYPESnumeric_to_double(numeric *, double *);
+int            PGTYPESnumeric_to_int(numeric *, int *);
+int            PGTYPESnumeric_to_long(numeric *, long *);
+int            PGTYPESnumeric_to_decimal(numeric *, decimal *);
+int            PGTYPESnumeric_from_decimal(decimal *, numeric *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /* PGTYPES_NUMERIC */
+
+#line 8 "outofscope.pgc"
+
+
+/* exec sql begin declare section */
+
+#line 1 "struct.h"
+
+  
+       
+       
+        /* dec_t */
+       
+       
+
+   typedef struct mytype  MYTYPE ;
+
+#line 9 "struct.h"
+
+
+  
+       
+       
+       
+       
+       
+
+   typedef struct mynulltype  MYNULLTYPE ;
+
+#line 18 "struct.h"
+
+
+#line 11 "outofscope.pgc"
+
+struct mytype { 
+#line 3 "struct.h"
+ int id ;
+#line 4 "struct.h"
+ char t [ 64 ] ;
+#line 5 "struct.h"
+ double d1 ;
+#line 6 "struct.h"
+ double d2 ;
+#line 7 "struct.h"
+ char c [ 30 ] ;
+ } ; struct mynulltype { 
+#line 12 "struct.h"
+ int id ;
+#line 13 "struct.h"
+ int t ;
+#line 14 "struct.h"
+ int d1 ;
+#line 15 "struct.h"
+ int d2 ;
+#line 16 "struct.h"
+ int c ;
+ } ;/* exec sql end declare section */
+#line 12 "outofscope.pgc"
+
+
+/* exec sql whenever sqlerror  stop ; */
+#line 14 "outofscope.pgc"
+
+
+/* Functions for test 1 */
+
+static void
+get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
+{
+   /* exec sql begin declare section */
+             
+         
+   
+#line 22 "outofscope.pgc"
+ MYTYPE * myvar = malloc ( sizeof ( MYTYPE ) ) ;
+#line 23 "outofscope.pgc"
+ MYNULLTYPE * mynullvar = malloc ( sizeof ( MYNULLTYPE ) ) ;
+/* exec sql end declare section */
+#line 24 "outofscope.pgc"
+
+
+   /* Test DECLARE ... SELECT ... INTO with pointers */
+
+   ECPGset_var( 0, ( myvar ), __LINE__);\
+ ECPGset_var( 1, ( mynullvar ), __LINE__);\
+ /* declare mycur cursor for select * from a1 */
+#line 28 "outofscope.pgc"
+
+
+   if (sqlca.sqlcode != 0)
+       exit(1);
+
+   *myvar0 = myvar;
+   *mynullvar0 = mynullvar;
+}
+
+static void
+open_cur1(void)
+{
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
+   ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0))).id),(long)1,(long)1,sizeof(int), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).id),(long)1,(long)1,sizeof(int), 
+   ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0))).t),(long)64,(long)1,(64)*sizeof(char), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).t),(long)1,(long)1,sizeof(int), 
+   ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0))).d1),(long)1,(long)1,sizeof(double), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).d1),(long)1,(long)1,sizeof(int), 
+   ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0))).d2),(long)1,(long)1,sizeof(double), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).d2),(long)1,(long)1,sizeof(int), 
+   ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0))).c),(long)30,(long)1,(30)*sizeof(char), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
+#line 40 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 40 "outofscope.pgc"
+
+
+   if (sqlca.sqlcode != 0)
+       exit(1);
+}
+
+static void
+get_record1(void)
+{
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
+   ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0))).id),(long)1,(long)1,sizeof(int), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).id),(long)1,(long)1,sizeof(int), 
+   ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0))).t),(long)64,(long)1,(64)*sizeof(char), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).t),(long)1,(long)1,sizeof(int), 
+   ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0))).d1),(long)1,(long)1,sizeof(double), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).d1),(long)1,(long)1,sizeof(int), 
+   ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0))).d2),(long)1,(long)1,sizeof(double), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).d2),(long)1,(long)1,sizeof(int), 
+   ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0))).c),(long)30,(long)1,(30)*sizeof(char), 
+   ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1))).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
+#line 49 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 49 "outofscope.pgc"
+
+
+   if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
+       exit(1);
+}
+
+static void
+close_cur1(void)
+{
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
+#line 58 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 58 "outofscope.pgc"
+
+
+   if (sqlca.sqlcode != 0)
+       exit(1);
+}
+
+int
+main (void)
+{
+   MYTYPE      *myvar;
+   MYNULLTYPE  *mynullvar;
+
+   char msg[128];
+
+   ECPGdebug(1, stderr);
+
+   strcpy(msg, "connect");
+   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
+#line 75 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 75 "outofscope.pgc"
+
+
+   strcpy(msg, "set");
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
+#line 78 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 78 "outofscope.pgc"
+
+
+   strcpy(msg, "create");
+   { 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);
+#line 81 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 81 "outofscope.pgc"
+
+
+   strcpy(msg, "insert");
+   { 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);
+#line 84 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 84 "outofscope.pgc"
+
+   { 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);
+#line 85 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 85 "outofscope.pgc"
+
+   { 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);
+#line 86 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 86 "outofscope.pgc"
+
+   { 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);
+#line 87 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 87 "outofscope.pgc"
+
+
+   strcpy(msg, "commit");
+   { ECPGtrans(__LINE__, NULL, "commit");
+#line 90 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 90 "outofscope.pgc"
+
+
+   /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
+
+   get_var1(&myvar, &mynullvar);
+   open_cur1();
+
+   /* exec sql whenever not found  break ; */
+#line 97 "outofscope.pgc"
+
+
+   while (1)
+   {
+       memset(myvar, 0, sizeof(MYTYPE));
+       get_record1();
+       if (sqlca.sqlcode == ECPG_NOT_FOUND)
+           break;
+       printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n",
+           myvar->id, mynullvar->id ? " (NULL)" : "",
+           myvar->t, mynullvar->t ? " (NULL)" : "",
+           myvar->d1, mynullvar->d1 ? " (NULL)" : "",
+           myvar->d2, mynullvar->d2 ? " (NULL)" : "",
+           myvar->c, mynullvar->c ? " (NULL)" : "");
+   }
+
+   close_cur1();
+
+   strcpy(msg, "drop");
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
+#line 116 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 116 "outofscope.pgc"
+
+
+   strcpy(msg, "commit");
+   { ECPGtrans(__LINE__, NULL, "commit");
+#line 119 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 119 "outofscope.pgc"
+
+
+   strcpy(msg, "disconnect"); 
+   { ECPGdisconnect(__LINE__, "CURRENT");
+#line 122 "outofscope.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 122 "outofscope.pgc"
+
+
+   return (0);
+}
diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.stderr b/src/interfaces/ecpg/test/expected/preproc-outofscope.stderr
new file mode 100644 (file)
index 0000000..c7dccbf
--- /dev/null
@@ -0,0 +1,136 @@
+[NO_PID]: ECPGdebug: set to 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>  
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 78: query: set datestyle to iso; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 78: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 78: OK: SET
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 81: query: create table a1 ( id serial primary key , t text , d1 numeric , d2 float8 , c character ( 10 ) ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 81: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 81: OK: CREATE TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 84: query: insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'a' , 1.0 , 2 , 'a' ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 84: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 84: OK: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 85: query: insert into a1 ( id , t , d1 , d2 , c ) values ( default , null , null , null , null ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 85: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 85: OK: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 86: query: insert into a1 ( id , t , d1 , d2 , c ) values ( default , '"a"' , - 1.0 , 'nan' :: float8 , 'a' ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 86: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 86: OK: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 87: query: insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'b' , 2.0 , 3 , 'b' ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 87: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 87: OK: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 90: action "commit"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 40: query: declare mycur cursor for select * from a1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 40: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 40: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: query: fetch mycur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: correctly got 1 tuples with 5 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 1 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: a offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 1.0 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 2 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: a          offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: query: fetch mycur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: correctly got 1 tuples with 5 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 2 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT:  offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT:  offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT:  offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT:  offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: query: fetch mycur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: correctly got 1 tuples with 5 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 3 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: "a" offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: -1.0 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: NaN offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: a          offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: query: fetch mycur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: correctly got 1 tuples with 5 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 4 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: b offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 2.0 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: 3 offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 49: RESULT: b          offset: -1; array: yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: query: fetch mycur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: correctly got 0 tuples with 5 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlcode 100 on line 49: no data found on line 49
+[NO_PID]: sqlca: code: 100, state: 02000
+[NO_PID]: ecpg_execute on line 58: query: close mycur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 58: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 58: OK: CLOSE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 116: query: drop table a1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 116: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 116: OK: DROP TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 119: action "commit"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_finish: connection regress1 closed
+[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.stdout b/src/interfaces/ecpg/test/expected/preproc-outofscope.stdout
new file mode 100644 (file)
index 0000000..636d491
--- /dev/null
@@ -0,0 +1,4 @@
+id=1 t='a' d1=1.000000 d2=2.000000 c = 'a         '
+id=2 t='' (NULL) d1=0.000000 (NULL) d2=0.000000 (NULL) c = '' (NULL)
+id=3 t='"a"' d1=-1.000000 d2=nan c = 'a         '
+id=4 t='b' d1=2.000000 d2=3.000000 c = 'b         '
diff --git a/src/interfaces/ecpg/test/preproc/outofscope.pgc b/src/interfaces/ecpg/test/preproc/outofscope.pgc
new file mode 100644 (file)
index 0000000..70fb6a6
--- /dev/null
@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+exec sql include ../regression;
+
+exec sql include pgtypes_numeric.h;
+
+exec sql begin declare section;
+exec sql include struct.h;
+exec sql end declare section;
+
+exec sql whenever sqlerror stop;
+
+/* Functions for test 1 */
+
+static void
+get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
+{
+   exec sql begin declare section;
+   MYTYPE      *myvar = malloc(sizeof(MYTYPE));
+   MYNULLTYPE  *mynullvar = malloc(sizeof(MYNULLTYPE));
+   exec sql end declare section;
+
+   /* Test DECLARE ... SELECT ... INTO with pointers */
+
+   exec sql declare mycur cursor for select * INTO :myvar :mynullvar from a1;
+
+   if (sqlca.sqlcode != 0)
+       exit(1);
+
+   *myvar0 = myvar;
+   *mynullvar0 = mynullvar;
+}
+
+static void
+open_cur1(void)
+{
+   exec sql open mycur;
+
+   if (sqlca.sqlcode != 0)
+       exit(1);
+}
+
+static void
+get_record1(void)
+{
+   exec sql fetch mycur;
+
+   if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
+       exit(1);
+}
+
+static void
+close_cur1(void)
+{
+   exec sql close mycur;
+
+   if (sqlca.sqlcode != 0)
+       exit(1);
+}
+
+int
+main (void)
+{
+   MYTYPE      *myvar;
+   MYNULLTYPE  *mynullvar;
+
+   char msg[128];
+
+   ECPGdebug(1, stderr);
+
+   strcpy(msg, "connect");
+   exec sql connect to REGRESSDB1;
+
+   strcpy(msg, "set");
+   exec sql set datestyle to iso;
+
+   strcpy(msg, "create");
+   exec sql create table a1(id serial primary key, t text, d1 numeric, d2 float8, c character(10));
+
+   strcpy(msg, "insert");
+   exec sql insert into a1(id, t, d1, d2, c) values (default, 'a', 1.0, 2, 'a');
+   exec sql insert into a1(id, t, d1, d2, c) values (default, null, null, null, null);
+   exec sql insert into a1(id, t, d1, d2, c) values (default, '"a"', -1.0, 'nan'::float8, 'a');
+   exec sql insert into a1(id, t, d1, d2, c) values (default, 'b', 2.0, 3, 'b');
+
+   strcpy(msg, "commit");
+   exec sql commit;
+
+   /* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
+
+   get_var1(&myvar, &mynullvar);
+   open_cur1();
+
+   exec sql whenever not found do break;
+
+   while (1)
+   {
+       memset(myvar, 0, sizeof(MYTYPE));
+       get_record1();
+       if (sqlca.sqlcode == ECPG_NOT_FOUND)
+           break;
+       printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n",
+           myvar->id, mynullvar->id ? " (NULL)" : "",
+           myvar->t, mynullvar->t ? " (NULL)" : "",
+           myvar->d1, mynullvar->d1 ? " (NULL)" : "",
+           myvar->d2, mynullvar->d2 ? " (NULL)" : "",
+           myvar->c, mynullvar->c ? " (NULL)" : "");
+   }
+
+   close_cur1();
+
+   strcpy(msg, "drop");
+   exec sql drop table a1;
+
+   strcpy(msg, "commit");
+   exec sql commit;
+
+   strcpy(msg, "disconnect"); 
+   exec sql disconnect;
+
+   return (0);
+}
diff --git a/src/interfaces/ecpg/test/preproc/struct.h b/src/interfaces/ecpg/test/preproc/struct.h
new file mode 100644 (file)
index 0000000..cc4681b
--- /dev/null
@@ -0,0 +1,18 @@
+
+struct mytype {
+   int id;
+   char    t[64];
+   double  d1; /* dec_t */
+   double  d2;
+   char    c[30];
+};
+typedef struct mytype MYTYPE;
+
+struct mynulltype {
+   int id;
+   int t;
+   int d1;
+   int d2;
+   int c;
+};
+typedef struct mynulltype MYNULLTYPE;