1#include <stdio.h> 2 3exec sql include ../regression; 4 5EXEC SQL WHENEVER sqlerror sqlprint; 6EXEC SQL WHENEVER sqlwarning sqlprint; 7EXEC SQL WHENEVER not found sqlprint; 8 9EXEC SQL TYPE customer IS 10 struct 11 { 12 varchar name[50]; 13 int phone; 14 }; 15 16EXEC SQL TYPE cust_ind IS 17 struct ind 18 { 19 short name_ind; 20 short phone_ind; 21 }; 22 23int main() 24{ 25 EXEC SQL begin declare section; 26 customer custs1[10]; 27 cust_ind inds[10]; 28 typedef struct 29 { 30 varchar name[50]; 31 int phone; 32 } customer2; 33 customer2 custs2[10]; 34 struct customer3 35 { 36 varchar name[50]; 37 int phone; 38 } custs3[10]; 39 struct customer4 40 { 41 varchar name[50]; 42 int phone; 43 } custs4; 44 int r; 45 varchar onlyname[2][50]; 46 EXEC SQL end declare section; 47 48 ECPGdebug(1, stderr); 49 50 EXEC SQL connect to REGRESSDB1; 51 52 EXEC SQL create table customers (c varchar(50), p int); 53 EXEC SQL insert into customers values ('John Doe', '12345'); 54 EXEC SQL insert into customers values ('Jane Doe', '67890'); 55 56 EXEC SQL select * INTO :custs1:inds from customers limit 2; 57 printf("custs1:\n"); 58 for (r = 0; r < 2; r++) 59 { 60 printf( "name - %s\n", custs1[r].name.arr ); 61 printf( "phone - %d\n", custs1[r].phone ); 62 } 63 64 EXEC SQL select * INTO :custs2:inds from customers limit 2; 65 printf("\ncusts2:\n"); 66 for (r = 0; r < 2; r++) 67 { 68 printf( "name - %s\n", custs2[r].name.arr ); 69 printf( "phone - %d\n", custs2[r].phone ); 70 } 71 72 EXEC SQL select * INTO :custs3:inds from customers limit 2; 73 printf("\ncusts3:\n"); 74 for (r = 0; r < 2; r++) 75 { 76 printf( "name - %s\n", custs3[r].name.arr ); 77 printf( "phone - %d\n", custs3[r].phone ); 78 } 79 80 EXEC SQL select * INTO :custs4:inds[0] from customers limit 1; 81 printf("\ncusts4:\n"); 82 printf( "name - %s\n", custs4.name.arr ); 83 printf( "phone - %d\n", custs4.phone ); 84 85 EXEC SQL select c INTO :onlyname from customers limit 2; 86 printf("\nname:\n"); 87 for (r = 0; r < 2; r++) 88 { 89 printf( "name - %s\n", onlyname[r].arr ); 90 } 91 92 EXEC SQL disconnect all; 93 94 return 0; 95} 96