aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test')
-rw-r--r--src/interfaces/ecpg/test/Makefile10
-rw-r--r--src/interfaces/ecpg/test/test_informix2.pgc123
2 files changed, 131 insertions, 2 deletions
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index 79ac9049d61..ad146549215 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.50 2005/06/30 07:01:57 neilc Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.51 2006/01/24 11:01:38 meskes Exp $
subdir = src/interfaces/ecpg/test
top_builddir = ../../../..
@@ -11,7 +11,7 @@ ECPG = ../preproc/ecpg -I$(srcdir)/../include
TESTS = test1 test2 test3 test4 test5 perftest dyntest dyntest2 test_notice \
test_code100 test_init testdynalloc num_test dt_test test_informix \
- test_desc
+ test_informix2 test_desc
ifeq ($(enable_thread_safety), yes)
TESTS += test_thread test_thread_implicit
endif
@@ -24,11 +24,17 @@ all: $(TESTS)
test_informix: test_informix.o
$(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@
+test_informix2: test_informix2.o
+ $(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@
+
%.c: %.pgc
$(ECPG) -o $@ -I$(srcdir) $<
test_informix.c: test_informix.pgc
$(ECPG) -o $@ -C INFORMIX -r no_indicator $<
+test_informix2.c: test_informix2.pgc
+ $(ECPG) -o $@ -C INFORMIX $<
+
clean:
rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log
diff --git a/src/interfaces/ecpg/test/test_informix2.pgc b/src/interfaces/ecpg/test/test_informix2.pgc
new file mode 100644
index 00000000000..b95ea5076f2
--- /dev/null
+++ b/src/interfaces/ecpg/test/test_informix2.pgc
@@ -0,0 +1,123 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "sqltypes.h"
+
+EXEC SQL include sqlca.h;
+
+/* Check SQLCODE, and produce a "standard error" if it's wrong! */
+static void sql_check(char *fn, char *caller, int ignore)
+{
+ char errorstring[255];
+
+ if (SQLCODE == ignore)
+ return;
+ else
+ {
+ if (SQLCODE != 0)
+ {
+
+ sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
+ SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
+ fprintf(stderr, "%s", errorstring);
+ printf("%s\n", errorstring);
+
+ /* attempt a ROLLBACK */
+ EXEC SQL rollback;
+
+ if (SQLCODE == 0)
+ {
+ sprintf(errorstring, "Rollback successful.\n");
+ } else {
+ sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
+ }
+
+ fprintf(stderr, "%s", errorstring);
+ printf("%s\n", errorstring);
+
+ exit(1);
+ }
+ }
+}
+
+
+
+int main(void)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ int c;
+ timestamp d;
+ timestamp maxd;
+ char dbname[30];
+ EXEC SQL END DECLARE SECTION;
+
+ EXEC SQL whenever sqlerror sqlprint;
+
+ strcpy(dbname, "mm");
+ EXEC SQL connect to :dbname;
+ sql_check("main", "connect", 0);
+
+ EXEC SQL create table history (customerid integer, timestamp timestamp without time zone, action_taken char(5), narrative varchar(100));
+ sql_check("main", "create", 0);
+
+ EXEC SQL insert into history
+ (customerid, timestamp, action_taken, narrative)
+ values(1, now(), 'test', 'test');
+ sql_check("main", "insert", 0);
+
+ EXEC SQL select max(timestamp)
+ into :maxd
+ from history;
+ sql_check("main", "select max", 100);
+
+ if (risnull(CDTIMETYPE, (char *) &maxd))
+ {
+ printf("Nothing on the history table\n\n");
+ exit(0);
+ }
+
+ EXEC SQL select customerid, timestamp
+ into :c, :d
+ from history
+ where timestamp = :maxd
+ limit 1;
+ sql_check("main", "select", 0);
+
+ printf("Read in customer %d\n", c);
+
+ /* Adding 1 to d adds 1 second. So:
+ 60 1 minute
+ 3600 1 hour
+ 86400 1 day */
+ d=d+86400;
+ c++;
+
+ EXEC SQL insert into history
+ (customerid, timestamp, action_taken, narrative)
+ values(:c, :d, 'test', 'test');
+ sql_check("main", "update", 0);
+
+ EXEC SQL commit;
+
+ EXEC SQL drop table history;
+ sql_check("main", "drop", 0);
+
+ EXEC SQL commit;
+
+ EXEC SQL disconnect;
+ sql_check("main", "disconnect", 0);
+
+ printf("All OK!\n");
+
+ exit(0);
+
+/*
+ Table "public.history"
+ Column | Type | Modifiers
+--------------+-----------------------------+-----------
+ customerid | integer | not null
+ timestamp | timestamp without time zone | not null
+ action_taken | character(5) | not null
+ narrative | character varying(100) |
+*/
+
+}