summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/define.pgc
blob: ed58a4bde0c19166a66fd238a2940cbaee4ccf96 (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
exec sql include sqlca;
exec sql include ../regression;
exec sql define STR 'abcdef';
exec sql define INSERTNULL 1;
exec sql define NUMBER 29;

int main(void)
{
   exec sql begin declare section;
     int i;
     char s[200];
   exec sql end declare section;

   ECPGdebug(1, stderr);

   exec sql whenever sqlerror do sqlprint();
   exec sql connect to REGRESSDB1;

   exec sql create table test (a int, b text);
   exec sql insert into test values (NUMBER, STR);

   exec sql ifdef INSERTNULL;
   exec sql insert into test values (NULL, 'defined');
   exec sql endif;

   exec sql ifndef INSERTNULL;
   exec sql insert into test values (NULL, 'not defined');
   exec sql elif SOMEOTHERVAR;
   exec sql insert into test values (NULL, 'someothervar defined');
   exec sql else;
   exec sql insert into test values (NULL, 'someothervar not defined');
   exec sql endif;

   exec sql define NUMBER 29;

   exec sql select INSERTNULL, NUMBER::text || '-' || STR INTO :i, :s;

   printf("i: %d, s: %s\n", i, s);

   exec sql undef STR;
   exec sql ifndef STR;
   exec sql insert into test values (NUMBER, 'no string');
   exec sql endif;

   exec sql define TZVAR;  /* no value */
   exec sql define TZVAR 'UTC';

   exec sql ifndef TZVAR;
   exec sql SET TIMEZONE TO 'GMT';
   exec sql elif TZNAME;
   exec sql SET TIMEZONE TO TZNAME;
   exec sql else;
   exec sql SET TIMEZONE TO TZVAR;
   exec sql endif;

   exec sql disconnect;
   return 0;
}