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
|
#include <stdio.h>
exec sql include sqlca;
exec sql include ../regression;
int main()
{
exec sql begin declare section;
int intvar = 5;
int nullind = -1;
exec sql end declare section;
ECPGdebug(1,stderr);
exec sql connect to REGRESSDB1;
exec sql set autocommit to off;
exec sql create table indicator_test (
"id" int primary key,
"str" text NOT NULL,
val int null);
exec sql commit work;
exec sql insert into indicator_test (id, str, val) values ( 1, 'Hello', 0);
/* use indicator in insert */
exec sql insert into indicator_test (id, str, val) values ( 2, 'Hi there', :intvar :nullind);
nullind = 0;
exec sql insert into indicator_test (id, str, val) values ( 3, 'Good evening', :intvar :nullind);
exec sql commit work;
/* use indicators to get information about selects */
exec sql select val into :intvar from indicator_test where id = 1;
exec sql select val into :intvar :nullind from indicator_test where id = 2;
printf("intvar: %d, nullind: %d\n", intvar, nullind);
exec sql select val into :intvar :nullind from indicator_test where id = 3;
printf("intvar: %d, nullind: %d\n", intvar, nullind);
/* use indicators for update */
intvar = 5; nullind = -1;
exec sql update indicator_test set val = :intvar :nullind where id = 1;
exec sql select val into :intvar :nullind from indicator_test where id = 1;
printf("intvar: %d, nullind: %d\n", intvar, nullind);
exec sql drop table indicator_test;
exec sql commit work;
exec sql disconnect;
return 0;
}
|