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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* test automatic prepare for all statements */
EXEC SQL INCLUDE ../regression;
static void test(void) {
EXEC SQL BEGIN DECLARE SECTION;
int item[4], ind[4], i = 1;
int item1, ind1;
char sqlstr[64] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST";
EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr);
EXEC SQL CONNECT TO REGRESSDB1;
EXEC SQL WHENEVER SQLWARNING SQLPRINT;
EXEC SQL WHENEVER SQLERROR SQLPRINT;
EXEC SQL CREATE TABLE T ( Item1 int, Item2 int );
EXEC SQL INSERT INTO T VALUES ( 1, null );
EXEC SQL INSERT INTO T VALUES ( 1, :i );
i++;
EXEC SQL INSERT INTO T VALUES ( 1, :i );
EXEC SQL PREPARE I AS INSERT INTO T VALUES ( 1, 2 );
EXEC SQL EXECUTE I;
EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST;
for (i=0; i<4; i++)
printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;
EXEC SQL OPEN C;
EXEC SQL FETCH 1 IN C INTO :i;
printf("i = %d\n", i);
EXEC SQL CLOSE C;
EXEC SQL PREPARE stmt1 FROM :sqlstr;
EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
EXEC SQL OPEN cur1;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
i = 0;
while (i < 100)
{
EXEC SQL FETCH cur1 INTO :item1:ind1;
printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
i++;
}
EXEC SQL CLOSE cur1;
EXEC SQL DROP TABLE T;
EXEC SQL DISCONNECT ALL;
}
int main() {
test();
test(); /* retry */
return 0;
}
|