| 1 |
#include <stdlib.h> |
| 2 |
|
| 3 |
exec sql include ../regression; |
| 4 |
|
| 5 |
exec sql whenever sqlerror stop; |
| 6 |
|
| 7 |
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 |
ECPGdebug(1, stderr); |
| 21 |
|
| 22 |
strcpy(msg, "connect"); |
| 23 |
exec sql connect to REGRESSDB1; |
| 24 |
|
| 25 |
strcpy(msg, "create"); |
| 26 |
exec sql create table emp(ename varchar,sal double precision, comm double precision); |
| 27 |
|
| 28 |
strcpy(msg, "insert"); |
| 29 |
exec sql insert into emp values ('Ram',111100,21); |
| 30 |
exec sql insert into emp values ('aryan',11110,null); |
| 31 |
exec sql insert into emp values ('josh',10000,10); |
| 32 |
exec sql insert into emp values ('tom',20000,null); |
| 33 |
|
| 34 |
exec sql declare c cursor for select ename, sal, comm from emp order by ename collate "C" asc; |
| 35 |
|
| 36 |
exec sql open c; |
| 37 |
|
| 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 |
for (loopcount = 0; loopcount < 100; loopcount++) |
| 45 |
{ |
| 46 |
exec sql fetch c into :emp; |
| 47 |
/* The employees with non-NULL commissions will be displayed. */ |
| 48 |
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 |
exec sql close c; |
| 58 |
|
| 59 |
strcpy(msg, "drop"); |
| 60 |
exec sql drop table emp; |
| 61 |
|
| 62 |
exit(0); |
| 63 |
} |