summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/preproc/whenever.pgc
blob: 6090e5fbd5a8e1c8f4559fbf14596c2b7f6a3e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
}