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
79
80
81
82
83
84
85
86
87
88
89
|
EXEC SQL INCLUDE ../regression;
EXEC SQL WHENEVER SQLERROR SQLPRINT;
int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
char *stmt1 = "INSERT INTO test1 VALUES ($1, $2)";
char *stmt2 = "SELECT * from test1 where a = $1 and b = $2";
char *stmt3 = "SELECT * from test1 where :var = a";
int val1 = 1;
char val2[4] = "one", val2output[] = "AAA";
int val1output = 2, val2i = 0;
int val2null = -1;
int ind1, ind2;
char desc1[8] = "outdesc";
EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr);
EXEC SQL ALLOCATE DESCRIPTOR indesc;
EXEC SQL ALLOCATE DESCRIPTOR :desc1;
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
EXEC SQL CONNECT TO REGRESSDB1;
EXEC SQL CREATE TABLE test1 (a int, b text);
EXEC SQL PREPARE foo1 FROM :stmt1;
EXEC SQL PREPARE "Foo-1" FROM :stmt1;
EXEC SQL PREPARE foo2 FROM :stmt2;
EXEC SQL PREPARE foo3 FROM :stmt3;
EXEC SQL EXECUTE foo1 USING SQL DESCRIPTOR indesc;
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2null, DATA = :val2;
EXEC SQL EXECUTE foo1 USING SQL DESCRIPTOR indesc;
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 3;
EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val1, DATA = 'this is a long test';
EXEC SQL EXECUTE "Foo-1" USING SQL DESCRIPTOR indesc;
EXEC SQL DEALLOCATE "Foo-1";
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
EXEC SQL EXECUTE foo2 USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR :desc1;
EXEC SQL GET DESCRIPTOR :desc1 VALUE 1 :val2output = DATA;
printf("output = %s\n", val2output);
EXEC SQL DECLARE c1 CURSOR FOR foo2;
EXEC SQL OPEN c1 USING SQL DESCRIPTOR indesc;
EXEC SQL FETCH next FROM c1 INTO :val1output:ind1, :val2output:ind2;
printf("val1=%d (ind1: %d) val2=%s (ind2: %d)\n",
val1output, ind1, val2output, ind2);
EXEC SQL CLOSE c1;
EXEC SQL SET DESCRIPTOR indesc COUNT = 1;
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
EXEC SQL DECLARE c2 CURSOR FOR foo3;
EXEC SQL OPEN c2 USING SQL DESCRIPTOR indesc;
EXEC SQL FETCH next FROM c2 INTO :val1output, :val2output :val2i;
printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
EXEC SQL CLOSE c2;
EXEC SQL SELECT * INTO :val1output, :val2output:val2i FROM test1 where a = 3;
printf("val1=%d val2=%c%c%c%c warn=%c truncate=%d\n", val1output, val2output[0], val2output[1], val2output[2], val2output[3], sqlca.sqlwarn[0], val2i);
EXEC SQL DROP TABLE test1;
EXEC SQL DEALLOCATE ALL;
EXEC SQL DISCONNECT;
EXEC SQL DEALLOCATE DESCRIPTOR indesc;
EXEC SQL DEALLOCATE DESCRIPTOR :desc1;
return 0;
}
|