aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2007-08-14 10:01:54 +0000
committerMichael Meskes <meskes@postgresql.org>2007-08-14 10:01:54 +0000
commit635a0b9a8640bb7f2944a3f77ddc370f8dd7b010 (patch)
treed54146b2416fecd2a544f3bf786108079b879cfc /src/interfaces/ecpg/test/preproc/array_of_struct.pgc
parentb83bd31bd953b6daa22bcbdaee5ade2a27ec7324 (diff)
downloadpostgresql-635a0b9a8640bb7f2944a3f77ddc370f8dd7b010.tar.gz
postgresql-635a0b9a8640bb7f2944a3f77ddc370f8dd7b010.zip
- Finished major rewrite to use new protocol version
- Really prepare statements - Added more regression tests - Added auto-prepare mode - Use '$n' for positional variables, '?' is still possible via ecpg option - Cleaned up the sources a little bit
Diffstat (limited to 'src/interfaces/ecpg/test/preproc/array_of_struct.pgc')
-rw-r--r--src/interfaces/ecpg/test/preproc/array_of_struct.pgc87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/preproc/array_of_struct.pgc b/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
new file mode 100644
index 00000000000..52f952d639f
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
@@ -0,0 +1,87 @@
+#include <stdio.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( int argc, char * argv[] )
+{
+ EXEC SQL begin declare section;
+ customer custs1[10];
+ cust_ind inds[10];
+ typedef struct
+ {
+ varchar name[50];
+ int phone;
+ } customer2;
+ customer2 custs2[10];
+ struct customer3
+ {
+ varchar name[50];
+ int phone;
+ } custs3[10];
+ struct customer4
+ {
+ varchar name[50];
+ int phone;
+ } custs4;
+ int r;
+ 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.arr );
+ printf( "phone - %d\n", custs3[r].phone );
+ }
+
+ EXEC SQL select * INTO :custs4:inds[0] from customers limit 1;
+ printf("\ncusts4:\n");
+ printf( "name - %s\n", custs4.name.arr );
+ printf( "phone - %d\n", custs4.phone );
+
+ EXEC SQL disconnect all;
+
+ return( 0 );
+}