summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/preproc/define.pgc
blob: 90dc32856ef98fe2332c960c53af4536b81883fd (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
68
69
70
71
72
73
74
75
76
77
78
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

exec sql include ../regression;

exec sql whenever sqlerror sqlprint;

exec sql define AMOUNT 6;
exec sql define NAMELEN 8;

exec sql type intarray is int[AMOUNT];
typedef int intarray[AMOUNT];

int
main(void)
{
exec sql begin declare section;

exec sql ifdef NAMELEN;
	typedef char string[NAMELEN];
	intarray amount;
	char name[AMOUNT][NAMELEN];
exec sql elif AMOUNT;
	should not get here;
exec sql else;
	should not get here either;
exec sql endif;

exec sql ifndef NAMELEN;
	should not get here;
exec sql elif AMOUNT;
  exec sql ifdef NOSUCHNAME;
	should not get here;
  exec sql else;
	char letter[AMOUNT][1];
#if 0
	int not_used;
#endif
  exec sql endif;
exec sql elif AMOUNT;
	should not get here;
exec sql endif;

exec sql end declare section;
	int i,j;

	ECPGdebug(1, stderr);

	exec sql connect to REGRESSDB1;

	exec sql create table test (name char(NAMELEN), amount int, letter char(1));
	exec sql commit;

	exec sql insert into Test (name, amount, letter) values ('false', 1, 'f');
	exec sql insert into test (name, amount, letter) values ('true', 2, 't');
	exec sql commit;

	exec sql select * into :name, :amount, :letter from test;

	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
	{
		exec sql begin declare section;
		string n;
		char l = letter[i][0];
		int a = amount[i];
		exec sql end declare section;

		strncpy(n, name[i], NAMELEN);
		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
	}

	exec sql drop table test;
	exec sql commit;
	exec sql disconnect;

	return 0;
}