Line data Source code
1 : #include <stdlib.h>
2 :
3 : exec sql include ../regression;
4 :
5 : exec sql whenever sqlerror stop;
6 :
7 2 : int main(void)
8 : {
9 : exec sql begin declare section;
10 : struct
11 : {
12 : char ename[12];
13 : float sal;
14 : float comm;
15 : } emp;
16 : int loopcount;
17 : char msg[128];
18 : exec sql end declare section;
19 :
20 2 : ECPGdebug(1, stderr);
21 :
22 2 : strcpy(msg, "connect");
23 2 : exec sql connect to REGRESSDB1;
24 2 :
25 2 : strcpy(msg, "create");
26 2 : exec sql create table emp(ename varchar,sal double precision, comm double precision);
27 2 :
28 2 : strcpy(msg, "insert");
29 2 : exec sql insert into emp values ('Ram',111100,21);
30 2 : exec sql insert into emp values ('aryan',11110,null);
31 2 : exec sql insert into emp values ('josh',10000,10);
32 2 : exec sql insert into emp values ('tom',20000,null);
33 2 :
34 : exec sql declare c cursor for select ename, sal, comm from emp order by ename collate "C" asc;
35 :
36 2 : exec sql open c;
37 2 :
38 : /* The 'BREAK' condition to exit the loop. */
39 : exec sql whenever not found do break;
40 :
41 : /* The DO CONTINUE makes the loop start at the next iteration when an error occurs.*/
42 : exec sql whenever sqlerror do continue;
43 :
44 10 : for (loopcount = 0; loopcount < 100; loopcount++)
45 : {
46 10 : exec sql fetch c into :emp;
47 10 : /* The employees with non-NULL commissions will be displayed. */
48 4 : printf("%s %7.2f %9.2f\n", emp.ename, emp.sal, emp.comm);
49 : }
50 :
51 : /*
52 : * This 'CONTINUE' shuts off the 'DO CONTINUE' and allow the program to
53 : * proceed if any further errors do occur.
54 : */
55 : exec sql whenever sqlerror continue;
56 :
57 2 : exec sql close c;
58 :
59 2 : strcpy(msg, "drop");
60 2 : exec sql drop table emp;
61 :
62 2 : exit(0);
63 : }
|