summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/preproc/whenever.pgc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/interfaces/ecpg/test/preproc/whenever.pgc
parentInitial commit. (diff)
downloadpostgresql-14-upstream.tar.xz
postgresql-14-upstream.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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);
+}