summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/preproc/outofscope.pgc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test/preproc/outofscope.pgc')
-rw-r--r--src/interfaces/ecpg/test/preproc/outofscope.pgc116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/preproc/outofscope.pgc b/src/interfaces/ecpg/test/preproc/outofscope.pgc
new file mode 100644
index 0000000..ed60782
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/outofscope.pgc
@@ -0,0 +1,116 @@
+#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;
+}
+
+static void
+get_record1(void)
+{
+ exec sql fetch mycur;
+}
+
+static void
+close_cur1(void)
+{
+ exec sql close mycur;
+}
+
+int
+main (void)
+{
+ MYTYPE *myvar;
+ MYNULLTYPE *mynullvar;
+ int loopcount;
+ 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, '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();
+
+ for (loopcount = 0; loopcount < 100; loopcount++)
+ {
+ memset(myvar, 0, sizeof(MYTYPE));
+ get_record1();
+ if (sqlca.sqlcode == ECPG_NOT_FOUND)
+ break;
+ printf("id=%d%s t='%s'%s d1=%f%s d2=%f%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();
+
+ free(myvar);
+ free(mynullvar);
+
+ strcpy(msg, "drop");
+ exec sql drop table a1;
+
+ strcpy(msg, "commit");
+ exec sql commit;
+
+ strcpy(msg, "disconnect");
+ exec sql disconnect;
+
+ return 0;
+}