1#include <stdlib.h> 2#include <string.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6exec sql include ../regression; 7 8exec sql whenever sqlerror sqlprint; 9 10int 11main(void) 12{ 13exec sql begin declare section; 14 int amount[8]; 15 int increment=100; 16 char name[8][8]; 17 char letter[8][1]; 18 char command[128]; 19exec sql end declare section; 20 int i,j; 21 22 ECPGdebug(1, stderr); 23 24 exec sql connect to REGRESSDB1 as main; 25 26 exec sql create table test (name char(8), amount int, letter char(1)); 27 exec sql commit; 28 29 sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')"); 30 exec sql execute immediate :command; 31 32 sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')"); 33 exec sql execute immediate :command; 34 35 sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test"); 36 exec sql execute immediate :command; 37 38 printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]); 39 40 sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test"); 41 exec sql prepare I from :command; 42 exec sql execute I using :increment; 43 44 printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]); 45 46 exec sql commit; 47 48 sprintf (command, "select * from test"); 49 50 exec sql prepare F from :command; 51 exec sql declare CUR cursor for F; 52 53 exec sql open CUR; 54 exec sql fetch 8 in CUR into :name, :amount, :letter; 55 56 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) 57 { 58 char n[8], l = letter[i][0]; 59 int a = amount[i]; 60 61 strncpy(n, name[i], 8); 62 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); 63 } 64 65 exec sql close CUR; 66 67 sprintf (command, "select * from test where ? = amount"); 68 69 exec sql prepare F from :command; 70 exec sql declare CUR3 cursor for F; 71 72 exec sql open CUR3 using 1; 73 exec sql fetch in CUR3 into :name, :amount, :letter; 74 75 for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) 76 { 77 char n[8], l = letter[i][0]; 78 int a = amount[i]; 79 80 strncpy(n, name[i], 8); 81 printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); 82 } 83 84 exec sql close CUR3; 85 exec sql drop table test; 86 exec sql commit; 87 exec sql disconnect; 88 89 return 0; 90} 91