summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/connect
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/interfaces/ecpg/test/connect/.gitignore10
-rw-r--r--src/interfaces/ecpg/test/connect/Makefile12
-rw-r--r--src/interfaces/ecpg/test/connect/README9
-rw-r--r--src/interfaces/ecpg/test/connect/test1.pgc65
-rw-r--r--src/interfaces/ecpg/test/connect/test2.pgc46
-rw-r--r--src/interfaces/ecpg/test/connect/test3.pgc52
-rw-r--r--src/interfaces/ecpg/test/connect/test4.pgc20
-rw-r--r--src/interfaces/ecpg/test/connect/test5.pgc76
8 files changed, 290 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/connect/.gitignore b/src/interfaces/ecpg/test/connect/.gitignore
new file mode 100644
index 0000000..e0639f3
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/.gitignore
@@ -0,0 +1,10 @@
+/test1
+/test1.c
+/test2
+/test2.c
+/test3
+/test3.c
+/test4
+/test4.c
+/test5
+/test5.c
diff --git a/src/interfaces/ecpg/test/connect/Makefile b/src/interfaces/ecpg/test/connect/Makefile
new file mode 100644
index 0000000..2602d5d
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/Makefile
@@ -0,0 +1,12 @@
+subdir = src/interfaces/ecpg/test/connect
+top_builddir = ../../../../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/$(subdir)/../Makefile.regress
+
+TESTS = test1 test1.c \
+ test2 test2.c \
+ test3 test3.c \
+ test4 test4.c \
+ test5 test5.c
+
+all: $(TESTS)
diff --git a/src/interfaces/ecpg/test/connect/README b/src/interfaces/ecpg/test/connect/README
new file mode 100644
index 0000000..3bbfbc5
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/README
@@ -0,0 +1,9 @@
+src/interfaces/ecpg/test/connect/README
+
+Programs in this directory test all sorts of connections.
+
+All other programs just use one standard connection method.
+
+If any details of the regression database get changed (port, unix socket file,
+user names, passwords, ...), these programs here have to be changed as well
+because they contain hardcoded values.
diff --git a/src/interfaces/ecpg/test/connect/test1.pgc b/src/interfaces/ecpg/test/connect/test1.pgc
new file mode 100644
index 0000000..961bd72
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/test1.pgc
@@ -0,0 +1,65 @@
+/*
+ * this file tests all sorts of connecting to one single database.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/* do not include regression.h */
+
+int
+main(void)
+{
+exec sql begin declare section;
+ char db[200];
+ char pw[200];
+exec sql end declare section;
+
+ ECPGdebug(1, stderr);
+
+ exec sql connect to ecpg2_regression as main;
+ exec sql alter user regress_ecpg_user1 ENCRYPTED PASSWORD 'connectpw';
+ exec sql disconnect; /* <-- "main" not specified */
+
+ exec sql connect to ecpg2_regression@localhost as main;
+ exec sql disconnect main;
+
+ exec sql connect to @localhost as main user regress_ecpg_user2;
+ exec sql disconnect main;
+
+ /* exec sql connect to :@TEMP_PORT@ as main user regress_ecpg_user2;
+ exec sql disconnect main; */
+
+ exec sql connect to tcp:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 identified by connectpw;
+ exec sql disconnect;
+
+ exec sql connect to tcp:postgresql://localhost/ user regress_ecpg_user2;
+ exec sql disconnect;
+
+ strcpy(pw, "connectpw");
+ strcpy(db, "tcp:postgresql://localhost/ecpg2_regression");
+ exec sql connect to :db user regress_ecpg_user1 using :pw;
+ exec sql disconnect;
+
+ exec sql connect to unix:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 using "connectpw";
+ exec sql disconnect;
+
+ exec sql connect to unix:postgresql://localhost/ecpg2_regression?connect_timeout=180 user regress_ecpg_user1;
+ exec sql disconnect;
+
+ /* wrong db */
+ exec sql connect to tcp:postgresql://localhost/nonexistent user regress_ecpg_user1 identified by connectpw;
+ exec sql disconnect;
+
+ /* wrong port */
+ exec sql connect to tcp:postgresql://127.0.0.1:20/ecpg2_regression user regress_ecpg_user1 identified by connectpw;
+ /* no disconnect necessary */
+
+ /* wrong password */
+ exec sql connect to unix:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 identified by "wrongpw";
+ /* no disconnect necessary */
+
+ return 0;
+}
diff --git a/src/interfaces/ecpg/test/connect/test2.pgc b/src/interfaces/ecpg/test/connect/test2.pgc
new file mode 100644
index 0000000..f31a7f9
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/test2.pgc
@@ -0,0 +1,46 @@
+/*
+ * this file tests multiple connections to databases and switches
+ * between them.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+exec sql include ../regression;
+
+int
+main(void)
+{
+exec sql begin declare section;
+ char id[200];
+ char res[200];
+exec sql end declare section;
+
+ ECPGdebug(1, stderr);
+
+ strcpy(id, "first");
+ exec sql connect to ecpg2_regression as :id;
+ exec sql connect to REGRESSDB1 as second;
+
+ /* this selects from "second" which was opened last */
+ exec sql select current_database() into :res;
+ exec sql at first select current_database() into :res;
+ exec sql at second select current_database() into :res;
+
+ exec sql set connection first;
+ exec sql select current_database() into :res;
+
+ /* this will disconnect from "first" */
+ exec sql disconnect;
+ exec sql select current_database() into :res;
+
+ /* error here since "first" is already disconnected */
+ exec sql disconnect :id;
+
+ /* disconnect from "second" */
+ exec sql disconnect;
+
+ return 0;
+}
diff --git a/src/interfaces/ecpg/test/connect/test3.pgc b/src/interfaces/ecpg/test/connect/test3.pgc
new file mode 100644
index 0000000..5d075f0
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/test3.pgc
@@ -0,0 +1,52 @@
+/*
+ * this file just tests the several possibilities you have for a disconnect
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+exec sql include ../regression;
+
+int
+main(void)
+{
+exec sql begin declare section;
+ char id[200];
+ char res[200];
+exec sql end declare section;
+
+ ECPGdebug(1, stderr);
+
+ strcpy(id, "first");
+ exec sql connect to ecpg2_regression as :id;
+ exec sql connect to REGRESSDB1 as second;
+
+ /* this selects from "second" which was opened last */
+ exec sql select current_database() into :res;
+
+ /* will close "second" */
+ exec sql disconnect CURRENT;
+ exec sql select current_database() into :res;
+
+ exec sql connect to REGRESSDB1 as second;
+ /* will close "second" */
+ exec sql disconnect DEFAULT;
+
+ exec sql connect to "ecpg2_regression" as second;
+ exec sql disconnect ALL;
+
+ exec sql disconnect CURRENT;
+ exec sql disconnect DEFAULT;
+ exec sql disconnect ALL;
+
+ /*
+ * exec sql disconnect;
+ * exec sql disconnect name;
+ *
+ * are used in other tests
+ */
+
+ return 0;
+}
diff --git a/src/interfaces/ecpg/test/connect/test4.pgc b/src/interfaces/ecpg/test/connect/test4.pgc
new file mode 100644
index 0000000..b20b174
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/test4.pgc
@@ -0,0 +1,20 @@
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+exec sql include ../regression;
+
+int
+main(void)
+{
+ ECPGdebug(1, stderr);
+
+ exec sql connect to REGRESSDB1 as main;
+
+ exec sql set connection to main;
+
+ exec sql disconnect DEFAULT;
+
+ return 0;
+}
diff --git a/src/interfaces/ecpg/test/connect/test5.pgc b/src/interfaces/ecpg/test/connect/test5.pgc
new file mode 100644
index 0000000..de29160
--- /dev/null
+++ b/src/interfaces/ecpg/test/connect/test5.pgc
@@ -0,0 +1,76 @@
+/*
+ * this file tests all sorts of connecting to one single database.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/* do not include regression.h */
+
+int
+main(void)
+{
+exec sql begin declare section;
+ char db[200];
+ char id[200];
+ char *user="regress_ecpg_user1";
+exec sql end declare section;
+
+ ECPGdebug(1, stderr);
+
+ exec sql connect to ecpg2_regression as main;
+ exec sql alter user regress_ecpg_user2 ENCRYPTED PASSWORD 'insecure';
+ exec sql alter user regress_ecpg_user1 ENCRYPTED PASSWORD 'connectpw';
+ exec sql commit;
+ exec sql disconnect; /* <-- "main" not specified */
+
+ strcpy(db, "ecpg2_regression");
+ strcpy(id, "main");
+ exec sql connect to :db as :id;
+ exec sql disconnect :id;
+
+ exec sql connect to ecpg2_regression as main;
+ exec sql disconnect main;
+
+ exec sql connect to "ecpg2_regression" as main;
+ exec sql disconnect main;
+
+ exec sql connect to 'ecpg2_regression' as main;
+ exec sql disconnect main;
+
+ /* exec sql connect to as main user regress_ecpg_user2/insecure;
+ exec sql disconnect main; */
+
+ exec sql connect to ecpg2_regression as main user regress_ecpg_user1/connectpw;
+ exec sql disconnect main;
+
+ exec sql connect to unix:postgresql://localhost/ecpg2_regression as main user regress_ecpg_user1/connectpw;
+ exec sql disconnect main;
+
+ exec sql connect to "unix:postgresql://localhost/ecpg2_regression" as main user regress_ecpg_user1/connectpw;
+ exec sql disconnect main;
+
+ exec sql connect to 'unix:postgresql://localhost/ecpg2_regression' as main user :user USING "connectpw";
+ exec sql disconnect main;
+
+ exec sql connect to unix:postgresql://localhost/ecpg2_regression?connect_timeout=180&client_encoding=latin1 as main user regress_ecpg_user1/connectpw;
+ exec sql disconnect main;
+
+ exec sql connect to "unix:postgresql://200.46.204.71/ecpg2_regression" as main user regress_ecpg_user1/connectpw;
+ exec sql disconnect main;
+
+ exec sql connect to "unix:postgresql://localhost/?gssencmode=disable" as main user regress_ecpg_user2 IDENTIFIED BY insecure;
+ exec sql disconnect main;
+
+ /* connect twice */
+ exec sql connect to ecpg2_regression as main;
+ exec sql connect to ecpg2_regression as main;
+ exec sql disconnect main;
+
+ /* not connected */
+ exec sql disconnect nonexistent;
+
+ return 0;
+}