Line data Source code
1 : #include <stdlib.h> 2 : #include <string.h> 3 : #include <stdio.h> 4 : 5 : exec sql include ../regression; 6 : 7 : exec sql whenever sqlerror sqlprint; 8 : 9 : exec sql define AMOUNT 6; 10 : exec sql define NAMELEN 8; 11 : 12 : exec sql type intarray is int[AMOUNT]; 13 : typedef int intarray[AMOUNT]; 14 : 15 : int 16 4 : main(void) 17 : { 18 : exec sql begin declare section; 19 : 20 : exec sql ifdef NAMELEN; 21 : typedef char string[NAMELEN]; 22 : intarray amount; 23 : char name[AMOUNT][NAMELEN]; 24 : exec sql elif AMOUNT; 25 : should not get here; 26 : exec sql else; 27 : should not get here either; 28 : exec sql endif; 29 : 30 : exec sql ifndef NAMELEN; 31 : should not get here; 32 : exec sql elif AMOUNT; 33 : exec sql ifdef NOSUCHNAME; 34 : should not get here; 35 : exec sql else; 36 : char letter[AMOUNT][1]; 37 : #if 0 38 : int not_used; 39 : #endif 40 : exec sql endif; 41 : exec sql elif AMOUNT; 42 : should not get here; 43 : exec sql endif; 44 : 45 : exec sql end declare section; 46 : int i,j; 47 : 48 4 : ECPGdebug(1, stderr); 49 : 50 4 : exec sql connect to REGRESSDB1; 51 4 : 52 4 : exec sql create table test (name char(NAMELEN), amount int, letter char(1)); 53 4 : exec sql commit; 54 4 : 55 4 : exec sql insert into Test (name, amount, letter) values ('false', 1, 'f'); 56 4 : exec sql insert into test (name, amount, letter) values ('true', 2, 't'); 57 4 : exec sql commit; 58 4 : 59 4 : exec sql select * into :name, :amount, :letter from test; 60 4 : 61 12 : for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) 62 : { 63 : exec sql begin declare section; 64 : string n; 65 8 : char l = letter[i][0]; 66 8 : int a = amount[i]; 67 : exec sql end declare section; 68 : 69 8 : strncpy(n, name[i], NAMELEN); 70 8 : printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); 71 : } 72 : 73 4 : exec sql drop table test; 74 4 : exec sql commit; 75 4 : exec sql disconnect; 76 4 : 77 4 : return 0; 78 : }