diff options
author | Michael Meskes <meskes@postgresql.org> | 2014-04-09 11:21:46 +0200 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2014-04-09 11:23:38 +0200 |
commit | f9179685371b74bf4752bf3f87846e5625cf91fa (patch) | |
tree | c02f67b1b93e0efb81db3ad7c36a8d1c0ba3892e /src/interfaces/ecpg/test/preproc/pointer_to_struct.pgc | |
parent | 0c4ea7a309249064b7c2a8b9612ee00f570f14af (diff) | |
download | postgresql-f9179685371b74bf4752bf3f87846e5625cf91fa.tar.gz postgresql-f9179685371b74bf4752bf3f87846e5625cf91fa.zip |
Several fixes to array handling in ecpg.
Patches by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Diffstat (limited to 'src/interfaces/ecpg/test/preproc/pointer_to_struct.pgc')
-rw-r--r-- | src/interfaces/ecpg/test/preproc/pointer_to_struct.pgc | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/preproc/pointer_to_struct.pgc b/src/interfaces/ecpg/test/preproc/pointer_to_struct.pgc new file mode 100644 index 00000000000..ec94273408b --- /dev/null +++ b/src/interfaces/ecpg/test/preproc/pointer_to_struct.pgc @@ -0,0 +1,100 @@ +#include <stdio.h> +#include <stdlib.h> + +exec sql include ../regression; + +EXEC SQL WHENEVER sqlerror sqlprint; +EXEC SQL WHENEVER sqlwarning sqlprint; +EXEC SQL WHENEVER not found sqlprint; + +EXEC SQL TYPE customer IS + struct + { + varchar name[50]; + int phone; + }; + +EXEC SQL TYPE cust_ind IS + struct ind + { + short name_ind; + short phone_ind; + }; + +int main() +{ + EXEC SQL begin declare section; + customer *custs1 = (customer *) malloc(sizeof(customer) * 10); + cust_ind *inds = (cust_ind *) malloc(sizeof(cust_ind) * 10); + typedef struct + { + varchar name[50]; + int phone; + } customer2; + customer2 *custs2 = (customer2 *) malloc(sizeof(customer2) * 10); + + struct customer3 + { + char name[50]; + int phone; + } *custs3 = (struct customer3 *) malloc(sizeof(struct customer3) * 10); + + struct customer4 + { + varchar name[50]; + int phone; + } *custs4 = (struct customer4 *) malloc(sizeof(struct customer4)); + + int r; + varchar onlyname[2][50]; + EXEC SQL end declare section; + + ECPGdebug(1, stderr); + + EXEC SQL connect to REGRESSDB1; + + EXEC SQL create table customers (c varchar(50), p int); + EXEC SQL insert into customers values ('John Doe', '12345'); + EXEC SQL insert into customers values ('Jane Doe', '67890'); + + EXEC SQL select * INTO :custs1:inds from customers limit 2; + printf("custs1:\n"); + for (r = 0; r < 2; r++) + { + printf( "name - %s\n", custs1[r].name.arr ); + printf( "phone - %d\n", custs1[r].phone ); + } + + EXEC SQL select * INTO :custs2:inds from customers limit 2; + printf("\ncusts2:\n"); + for (r = 0; r < 2; r++) + { + printf( "name - %s\n", custs2[r].name.arr ); + printf( "phone - %d\n", custs2[r].phone ); + } + + EXEC SQL select * INTO :custs3:inds from customers limit 2; + printf("\ncusts3:\n"); + for (r = 0; r < 2; r++) + { + printf( "name - %s\n", custs3[r].name ); + printf( "phone - %d\n", custs3[r].phone ); + } + + EXEC SQL select * INTO :custs4:inds from customers limit 1; + printf("\ncusts4:\n"); + printf( "name - %s\n", custs4->name.arr ); + printf( "phone - %d\n", custs4->phone ); + + EXEC SQL select c INTO :onlyname from customers limit 2; + printf("\nname:\n"); + for (r = 0; r < 2; r++) + { + printf( "name - %s\n", onlyname[r].arr ); + } + + EXEC SQL disconnect all; + + /* All the memory will anyway be freed at the end */ + return( 0 ); +} |