summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/preproc/whenever.pgc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test/preproc/whenever.pgc')
-rw-r--r--src/interfaces/ecpg/test/preproc/whenever.pgc67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/preproc/whenever.pgc b/src/interfaces/ecpg/test/preproc/whenever.pgc
new file mode 100644
index 0000000..6090e5f
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/whenever.pgc
@@ -0,0 +1,67 @@
+#include <stdlib.h>
+
+exec sql include ../regression;
+
+exec sql whenever sqlerror sqlprint;
+
+static void print(const char *msg)
+{
+ fprintf(stderr, "Error in statement '%s':\n", msg);
+ sqlprint();
+}
+
+static void print2(void)
+{
+ fprintf(stderr, "Found another error\n");
+ sqlprint();
+}
+
+static void warn(void)
+{
+ fprintf(stderr, "Warning: At least one column was truncated\n");
+}
+
+int main(void)
+{
+ exec sql int i;
+ exec sql char c[6];
+
+ ECPGdebug(1, stderr);
+
+ exec sql connect to REGRESSDB1;
+ exec sql create table test(i int, c char(10));
+ exec sql insert into test values(1, 'abcdefghij');
+
+ exec sql whenever sqlwarning do warn();
+ exec sql select * into :i, :c from test;
+ exec sql rollback;
+
+ exec sql select * into :i from nonexistent;
+ exec sql rollback;
+
+ exec sql whenever sqlerror do print("select");
+ exec sql select * into :i from nonexistent;
+ exec sql rollback;
+
+ exec sql whenever sqlerror call print2();
+ exec sql select * into :i from nonexistent;
+ exec sql rollback;
+
+ exec sql whenever sqlerror continue;
+ exec sql select * into :i from nonexistent;
+ exec sql rollback;
+
+ exec sql whenever sqlerror goto error;
+ exec sql select * into :i from nonexistent;
+ printf("Should not be reachable\n");
+
+ error:
+ exec sql rollback;
+
+ exec sql whenever sqlerror stop;
+ /* This cannot fail, thus we don't get an exit value not equal 0. */
+ /* However, it still test the precompiler output. */
+ exec sql select 1 into :i;
+ exec sql rollback;
+ exit (0);
+}