2007-01-11 15:47:34 +00:00
/* Processed by ecpg (regression mode) */
2006-09-08 09:03:40 +00:00
/* These include files are added by the preprocessor */
# include <ecpgtype.h>
# include <ecpglib.h>
# include <ecpgerrno.h>
# include <sqlca.h>
/* End of automatic include section */
2007-01-12 10:00:14 +00:00
# define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
2006-09-08 09:03:40 +00:00
# line 1 "variable.pgc"
# include <stdlib.h>
# include <string.h>
# line 1 "regression.h"
# line 4 "variable.pgc"
2007-05-27 11:32:59 +00:00
/* exec sql whenever sqlerror stop ; */
2006-09-08 09:03:40 +00:00
# line 6 "variable.pgc"
2006-10-04 10:09:03 +00:00
/* exec sql type c is char reference */
2006-09-08 09:03:40 +00:00
# line 8 "variable.pgc"
2006-10-04 10:09:03 +00:00
typedef char * c ;
2006-09-08 09:03:40 +00:00
2006-10-04 10:09:03 +00:00
/* exec sql type ind is union {
2006-09-08 09:03:40 +00:00
# line 11 "variable.pgc"
2006-10-04 10:09:03 +00:00
int integer ;
2006-09-08 09:03:40 +00:00
# line 11 "variable.pgc"
2006-10-04 10:09:03 +00:00
short smallint ;
} */
2006-09-08 09:03:40 +00:00
# line 11 "variable.pgc"
2006-10-04 10:09:03 +00:00
typedef union { int integer ; short smallint ; } ind ;
2006-09-08 09:03:40 +00:00
# define BUFFERSIZ 8
2006-10-04 10:09:03 +00:00
/* exec sql type str is [ BUFFERSIZ ] */
2006-09-08 09:03:40 +00:00
# line 15 "variable.pgc"
2006-10-04 10:09:03 +00:00
/* declare cur cursor for select name , born , age , married , children from family */
2006-09-08 09:03:40 +00:00
# line 18 "variable.pgc"
int
2006-10-04 10:09:03 +00:00
main ( void )
2006-09-08 09:03:40 +00:00
{
2006-10-04 10:09:03 +00:00
struct birthinfo {
2006-09-08 09:03:40 +00:00
# line 23 "variable.pgc"
2006-10-04 10:09:03 +00:00
long born ;
2006-09-08 09:03:40 +00:00
# line 23 "variable.pgc"
2006-10-04 10:09:03 +00:00
short age ;
} ;
2006-09-08 09:03:40 +00:00
# line 23 "variable.pgc"
/* exec sql begin declare section */
2006-10-04 10:09:03 +00:00
2006-09-08 09:03:40 +00:00
# line 27 "variable.pgc"
2006-10-04 10:09:03 +00:00
struct personal_struct {
2006-09-08 09:03:40 +00:00
# line 25 "variable.pgc"
2006-10-04 10:09:03 +00:00
struct varchar_name { int len ; char arr [ BUFFERSIZ ] ; } name ;
2006-09-08 09:03:40 +00:00
# line 26 "variable.pgc"
2006-10-04 10:09:03 +00:00
struct birthinfo birth ;
} personal , * p ;
2006-09-08 09:03:40 +00:00
# line 30 "variable.pgc"
2006-10-04 10:09:03 +00:00
struct personal_indicator {
2006-09-08 09:03:40 +00:00
# line 28 "variable.pgc"
2006-10-04 10:09:03 +00:00
int ind_name ;
2006-09-08 09:03:40 +00:00
# line 29 "variable.pgc"
2006-10-04 10:09:03 +00:00
struct birthinfo ind_birth ;
} ind_personal , * i ;
2006-09-08 09:03:40 +00:00
# line 31 "variable.pgc"
2006-10-04 10:09:03 +00:00
ind ind_children ;
2006-09-08 09:03:40 +00:00
/* exec sql end declare section */
# line 32 "variable.pgc"
2006-10-04 10:09:03 +00:00
2006-09-08 09:03:40 +00:00
# line 34 "variable.pgc"
2006-10-04 10:09:03 +00:00
char * married = NULL ;
2006-09-08 09:03:40 +00:00
# line 34 "variable.pgc"
2006-10-04 10:09:03 +00:00
2006-09-08 09:03:40 +00:00
# line 35 "variable.pgc"
2006-10-04 10:09:03 +00:00
long ind_married ;
2006-09-08 09:03:40 +00:00
# line 35 "variable.pgc"
2006-10-04 10:09:03 +00:00
2006-09-08 09:03:40 +00:00
# line 36 "variable.pgc"
2006-10-04 10:09:03 +00:00
ind children ;
2006-09-08 09:03:40 +00:00
# line 36 "variable.pgc"
2006-10-04 10:09:03 +00:00
char msg [ 128 ] ;
2006-09-08 09:03:40 +00:00
2006-10-04 10:09:03 +00:00
ECPGdebug ( 1 , stderr ) ;
2006-09-08 09:03:40 +00:00
strcpy ( msg , " connect " ) ;
2007-03-17 19:25:24 +00:00
{ ECPGconnect ( __LINE__ , 0 , " regress1 " , NULL , NULL , NULL , 0 ) ;
2006-09-08 09:03:40 +00:00
# line 43 "variable.pgc"
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-08 09:03:40 +00:00
# line 43 "variable.pgc"
2006-09-26 07:56:57 +00:00
strcpy ( msg , " set " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " set datestyle to iso " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-08 09:03:40 +00:00
# line 46 "variable.pgc"
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-08 09:03:40 +00:00
# line 46 "variable.pgc"
2006-09-26 07:56:57 +00:00
strcpy ( msg , " create " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " create table family ( name char ( 8 ) , born integer , age smallint , married date , children integer ) " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-08 09:03:40 +00:00
# line 49 "variable.pgc"
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-08 09:03:40 +00:00
# line 49 "variable.pgc"
2006-09-26 07:56:57 +00:00
strcpy ( msg , " insert " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " insert into family ( name , married , children ) values ( 'Mum' , '19870714' , 3 ) " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 52 "variable.pgc"
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 52 "variable.pgc"
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " insert into family ( name , born , married , children ) values ( 'Dad' , '19610721' , '19870714' , 3 ) " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 53 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 53 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " insert into family ( name , age ) values ( 'Child 1' , 16 ) " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 54 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 54 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " insert into family ( name , age ) values ( 'Child 2' , 14 ) " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 55 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 55 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " insert into family ( name , age ) values ( 'Child 3' , 9 ) " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 56 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 56 "variable.pgc"
2006-09-08 09:03:40 +00:00
strcpy ( msg , " commit " ) ;
2006-10-04 10:09:03 +00:00
{ ECPGtrans ( __LINE__ , NULL , " commit " ) ;
2006-09-26 07:56:57 +00:00
# line 59 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 59 "variable.pgc"
2006-09-08 09:03:40 +00:00
strcpy ( msg , " open " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " declare cur cursor for select name , born , age , married , children from family " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 62 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 62 "variable.pgc"
2006-09-08 09:03:40 +00:00
2006-10-04 10:09:03 +00:00
/* exec sql whenever not found break ; */
2006-09-26 07:56:57 +00:00
# line 64 "variable.pgc"
2006-09-08 09:03:40 +00:00
2006-10-04 10:09:03 +00:00
p = & personal ;
i = & ind_personal ;
2006-09-08 09:03:40 +00:00
memset ( i , 0 , sizeof ( ind_personal ) ) ;
2006-10-04 10:09:03 +00:00
while ( 1 ) {
2006-09-08 09:03:40 +00:00
strcpy ( msg , " fetch " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " fetch cur " , ECPGt_EOIT ,
2006-10-04 10:09:03 +00:00
ECPGt_varchar , & ( p - > name ) , ( long ) BUFFERSIZ , ( long ) 1 , sizeof ( struct varchar_name ) ,
ECPGt_int , & ( i - > ind_name ) , ( long ) 1 , ( long ) 1 , sizeof ( int ) ,
ECPGt_long , & ( p - > birth . born ) , ( long ) 1 , ( long ) 1 , sizeof ( long ) ,
ECPGt_long , & ( i - > ind_birth . born ) , ( long ) 1 , ( long ) 1 , sizeof ( long ) ,
ECPGt_short , & ( p - > birth . age ) , ( long ) 1 , ( long ) 1 , sizeof ( short ) ,
ECPGt_short , & ( i - > ind_birth . age ) , ( long ) 1 , ( long ) 1 , sizeof ( short ) ,
ECPGt_char , & ( married ) , ( long ) 0 , ( long ) 1 , ( 1 ) * sizeof ( char ) ,
ECPGt_long , & ( ind_married ) , ( long ) 1 , ( long ) 1 , sizeof ( long ) ,
ECPGt_int , & ( children . integer ) , ( long ) 1 , ( long ) 1 , sizeof ( int ) ,
ECPGt_short , & ( ind_children . smallint ) , ( long ) 1 , ( long ) 1 , sizeof ( short ) , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 71 "variable.pgc"
2006-09-08 09:03:40 +00:00
2006-10-04 10:09:03 +00:00
if ( sqlca . sqlcode = = ECPG_NOT_FOUND ) break ;
2006-09-26 07:56:57 +00:00
# line 71 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 71 "variable.pgc"
2006-09-08 09:03:40 +00:00
printf ( " %8.8s " , personal . name . arr ) ;
if ( i - > ind_birth . born > = 0 )
printf ( " , born %ld " , personal . birth . born ) ;
if ( i - > ind_birth . age > = 0 )
printf ( " , age = %d " , personal . birth . age ) ;
if ( ind_married > = 0 )
printf ( " , married %s " , married ) ;
if ( ind_children . smallint > = 0 )
printf ( " , children = %d " , children . integer ) ;
putchar ( ' \n ' ) ;
free ( married ) ;
married = NULL ;
}
strcpy ( msg , " close " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " close cur " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 88 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 88 "variable.pgc"
2006-09-08 09:03:40 +00:00
strcpy ( msg , " drop " ) ;
2007-05-27 15:59:57 +00:00
{ ECPGdo ( __LINE__ , 0 , 1 , NULL , " drop table family " , ECPGt_EOIT , ECPGt_EORT ) ;
2006-09-26 07:56:57 +00:00
# line 91 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 91 "variable.pgc"
2006-09-08 09:03:40 +00:00
strcpy ( msg , " commit " ) ;
2006-10-04 10:09:03 +00:00
{ ECPGtrans ( __LINE__ , NULL , " commit " ) ;
2006-09-26 07:56:57 +00:00
# line 94 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 94 "variable.pgc"
2006-09-08 09:03:40 +00:00
2006-10-04 10:09:03 +00:00
strcpy ( msg , " disconnect " ) ;
{ ECPGdisconnect ( __LINE__ , " CURRENT " ) ;
2006-09-26 07:56:57 +00:00
# line 97 "variable.pgc"
2006-09-08 09:03:40 +00:00
2007-05-27 11:32:59 +00:00
if ( sqlca . sqlcode < 0 ) exit ( 1 ) ; }
2006-09-26 07:56:57 +00:00
# line 97 "variable.pgc"
2006-09-08 09:03:40 +00:00
return ( 0 ) ;
}