summaryrefslogtreecommitdiff
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_thread.pgc70
2 files changed, 75 insertions, 5 deletions
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index 357779863d..ce87542846 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,22 +1,22 @@
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.39 2003/08/01 13:53:36 petere Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.40 2003/08/06 02:19:51 momjian Exp $
subdir = src/interfaces/ecpg/test
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
-override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS)
+override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CFLAGS)
ECPG = ../preproc/ecpg -I$(srcdir)/../include
-TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc num_test dt_test test_informix
+TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc num_test dt_test test_informix test_thread
all: $(TESTS)
%: %.o
- $(CC) $(CFLAGS) $(LDFLAGS) -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lpq -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lpq $(THREAD_LIBS) -o $@
test_informix: test_informix.o
- $(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(THREAD_LIBS) -o $@
%.c: %.pgc
$(ECPG) $<
diff --git a/src/interfaces/ecpg/test/test_thread.pgc b/src/interfaces/ecpg/test/test_thread.pgc
new file mode 100644
index 0000000000..828d66c6a8
--- /dev/null
+++ b/src/interfaces/ecpg/test/test_thread.pgc
@@ -0,0 +1,70 @@
+/* ---
+ * Thread test program
+ * by Philip Yarra
+ *
+ * To run, create this table in the 'test' database:
+ *
+ * CREATE TABLE foo (
+ * message character(40)
+ * );
+ * ---
+ */
+
+
+#include <pthread.h>
+
+int main(void);
+void ins1(void);
+void ins2(void);
+
+int main(void)
+{
+ pthread_t thread1, thread2;
+ pthread_create(&thread1, NULL, (void *) ins1, NULL);
+ pthread_create(&thread2, NULL, (void *) ins2, NULL);
+ pthread_join(thread1, NULL);
+ pthread_join(thread2, NULL);
+ printf("Program done!\n");
+ return 0;
+}
+
+void ins1(void)
+{
+ int i;
+ EXEC SQL BEGIN DECLARE SECTION;
+ char* cs = "test";
+ char* bar = "one!";
+ EXEC SQL END DECLARE SECTION;
+ EXEC SQL WHENEVER sqlerror sqlprint;
+ EXEC SQL CONNECT TO :cs AS test1;
+ for (i = 0; i < 5; i++)
+ {
+ printf("thread 1 : inserting\n");
+ EXEC SQL AT test1 INSERT INTO foo VALUES(:bar);
+ printf("thread 1 : insert done\n");
+ }
+ EXEC SQL AT test1 COMMIT WORK;
+ EXEC SQL DISCONNECT test1;
+ printf("thread 1 : done!\n");
+}
+
+
+void ins2(void)
+{
+ int i;
+ EXEC SQL BEGIN DECLARE SECTION;
+ char* cs = "test";
+ char* bar = "two!";
+ EXEC SQL END DECLARE SECTION;
+ EXEC SQL WHENEVER sqlerror sqlprint;
+ EXEC SQL CONNECT TO :cs AS test2;
+ for (i = 0; i < 5; i++)
+ {
+ printf("thread 2: inserting\n");
+ EXEC SQL AT test2 INSERT INTO foo VALUES(:bar);
+ printf("thread 2: insert done\n");
+ }
+ EXEC SQL AT test2 COMMIT WORK;
+ EXEC SQL DISCONNECT test2;
+ printf("thread 2: done!\n");
+}