aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/preproc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test/preproc')
-rw-r--r--src/interfaces/ecpg/test/preproc/Makefile10
-rw-r--r--src/interfaces/ecpg/test/preproc/array_of_struct.pgc87
-rw-r--r--src/interfaces/ecpg/test/preproc/autoprep.pgc47
3 files changed, 143 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/test/preproc/Makefile b/src/interfaces/ecpg/test/preproc/Makefile
index 937f89ca52a..6928a1f3fe3 100644
--- a/src/interfaces/ecpg/test/preproc/Makefile
+++ b/src/interfaces/ecpg/test/preproc/Makefile
@@ -4,7 +4,9 @@ include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/$(subdir)/../Makefile.regress
-TESTS = comment comment.c \
+TESTS = array_of_struct array_of_struct.c \
+ autoprep autoprep.c \
+ comment comment.c \
define define.c \
init init.c \
type type.c \
@@ -13,3 +15,9 @@ TESTS = comment comment.c \
all: $(TESTS)
+array_of_struct.c: array_of_struct.pgc ../regression.h
+ $(ECPG) -c -o $@ -I$(srcdir) $<
+
+autoprep.c: autoprep.pgc ../regression.h
+ $(ECPG) -r prepare -o $@ -I$(srcdir) $<
+
diff --git a/src/interfaces/ecpg/test/preproc/array_of_struct.pgc b/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
new file mode 100644
index 00000000000..52f952d639f
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
@@ -0,0 +1,87 @@
+#include <stdio.h>
+
+exec sql include ../regression;
+
+EXEC SQL WHENEVER sqlerror sqlprint;
+EXEC SQL WHENEVER sqlwarning sqlprint;
+EXEC SQL WHENEVER not found sqlprint;
+
+EXEC SQL TYPE customer IS
+ struct
+ {
+ varchar name[50];
+ int phone;
+ };
+
+EXEC SQL TYPE cust_ind IS
+ struct ind
+ {
+ short name_ind;
+ short phone_ind;
+ };
+
+int main( int argc, char * argv[] )
+{
+ EXEC SQL begin declare section;
+ customer custs1[10];
+ cust_ind inds[10];
+ typedef struct
+ {
+ varchar name[50];
+ int phone;
+ } customer2;
+ customer2 custs2[10];
+ struct customer3
+ {
+ varchar name[50];
+ int phone;
+ } custs3[10];
+ struct customer4
+ {
+ varchar name[50];
+ int phone;
+ } custs4;
+ int r;
+ EXEC SQL end declare section;
+
+ ECPGdebug(1, stderr);
+
+ EXEC SQL connect to REGRESSDB1;
+
+ EXEC SQL create table customers (c varchar(50), p int);
+ EXEC SQL insert into customers values ('John Doe', '12345');
+ EXEC SQL insert into customers values ('Jane Doe', '67890');
+
+ EXEC SQL select * INTO :custs1:inds from customers limit 2;
+ printf("custs1:\n");
+ for (r = 0; r < 2; r++)
+ {
+ printf( "name - %s\n", custs1[r].name.arr );
+ printf( "phone - %d\n", custs1[r].phone );
+ }
+
+ EXEC SQL select * INTO :custs2:inds from customers limit 2;
+ printf("\ncusts2:\n");
+ for (r = 0; r < 2; r++)
+ {
+ printf( "name - %s\n", custs2[r].name.arr );
+ printf( "phone - %d\n", custs2[r].phone );
+ }
+
+ EXEC SQL select * INTO :custs3:inds from customers limit 2;
+ printf("\ncusts3:\n");
+ for (r = 0; r < 2; r++)
+ {
+ printf( "name - %s\n", custs3[r].name.arr );
+ printf( "phone - %d\n", custs3[r].phone );
+ }
+
+ EXEC SQL select * INTO :custs4:inds[0] from customers limit 1;
+ printf("\ncusts4:\n");
+ printf( "name - %s\n", custs4.name.arr );
+ printf( "phone - %d\n", custs4.phone );
+
+ EXEC SQL disconnect all;
+
+ return( 0 );
+}
diff --git a/src/interfaces/ecpg/test/preproc/autoprep.pgc b/src/interfaces/ecpg/test/preproc/autoprep.pgc
new file mode 100644
index 00000000000..d29c3d556d0
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/autoprep.pgc
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* test automatic prepare for all statements */
+EXEC SQL INCLUDE ../regression;
+
+int main(int argc, char* argv[]) {
+ EXEC SQL BEGIN DECLARE SECTION;
+ int item[4], ind[4], i = 1;
+ EXEC SQL END DECLARE SECTION;
+
+ ECPGdebug(1, stderr);
+ EXEC SQL CONNECT TO REGRESSDB1;
+
+ EXEC SQL WHENEVER SQLWARNING SQLPRINT;
+ EXEC SQL WHENEVER SQLERROR SQLPRINT;
+
+ EXEC SQL CREATE TABLE T ( Item1 int, Item2 int );
+
+ EXEC SQL INSERT INTO T VALUES ( 1, null );
+ EXEC SQL INSERT INTO T VALUES ( 1, :i );
+ i++;
+ EXEC SQL INSERT INTO T VALUES ( 1, :i );
+ EXEC SQL PREPARE I AS INSERT INTO T VALUES ( 1, 2 );
+ EXEC SQL EXECUTE I;
+
+ EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST;
+
+ for (i=0; i<4; i++)
+ printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
+
+ EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;
+
+ EXEC SQL OPEN C;
+
+ EXEC SQL FETCH 1 IN C INTO :i;
+ printf("i = %d\n", i);
+
+ EXEC SQL CLOSE C;
+
+ EXEC SQL DROP TABLE T;
+
+ EXEC SQL DISCONNECT ALL;
+
+ return 0;
+}