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
90
|
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
exec sql include ../regression;
exec sql whenever sqlerror sqlprint;
int
main(void)
{
exec sql begin declare section;
int amount[8];
int increment=100;
char name[8][8];
char letter[8][1];
char command[128];
exec sql end declare section;
int i,j;
ECPGdebug(1, stderr);
exec sql connect to REGRESSDB1 as main;
exec sql create table test (name char(8), amount int, letter char(1));
exec sql commit;
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
exec sql execute immediate :command;
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
exec sql execute immediate :command;
sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
exec sql execute immediate :command;
printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
exec sql prepare I from :command;
exec sql execute I using :increment;
printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
exec sql commit;
sprintf (command, "select * from test");
exec sql prepare F from :command;
exec sql declare CUR cursor for F;
exec sql open CUR;
exec sql fetch 8 in CUR into :name, :amount, :letter;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{
char n[8], l = letter[i][0];
int a = amount[i];
strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
}
exec sql close CUR;
sprintf (command, "select * from test where ? = amount");
exec sql prepare F from :command;
exec sql declare CUR3 cursor for F;
exec sql open CUR3 using 1;
exec sql fetch in CUR3 into :name, :amount, :letter;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{
char n[8], l = letter[i][0];
int a = amount[i];
strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
}
exec sql close CUR3;
exec sql drop table test;
exec sql commit;
exec sql disconnect;
return 0;
}
|