From 46651ce6fe013220ed397add242004d764fc0153 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:15:05 +0200 Subject: Adding upstream version 14.5. Signed-off-by: Daniel Baumann --- src/interfaces/ecpg/test/preproc/whenever.pgc | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/interfaces/ecpg/test/preproc/whenever.pgc (limited to 'src/interfaces/ecpg/test/preproc/whenever.pgc') 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 + +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); +} -- cgit v1.2.3