outofscope.c-compat

text/plain

Filename: outofscope.c-compat
Type: text/plain
Part: 3
Message: Re: CommitFest 2009-09, two weeks on
/* Processed by ecpg (4.5.0) */
/* These include files are added by the preprocessor */
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* Needed for informix compatibility */
#include <ecpg_informix.h>
/* End of automatic include section */

#line 1 "outofscope.ec"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

/* exec sql begin declare section */

#line 1 "./struct.h"

  
		
		
		 /* dec_t */
		
		

   typedef struct mytype  MYTYPE ;

#line 9 "./struct.h"


  
		
		
		
		
		

   typedef struct mynulltype  MYNULLTYPE ;

#line 18 "./struct.h"


#line 7 "outofscope.ec"

struct mytype { 
#line 3 "./struct.h"
 int id ;
 
#line 4 "./struct.h"
 char t [ 64 ] ;
 
#line 5 "./struct.h"
 double d1 ;
 
#line 6 "./struct.h"
 double d2 ;
 
#line 7 "./struct.h"
 char c [ 30 ] ;
 } ; struct mynulltype { 
#line 12 "./struct.h"
 int id ;
 
#line 13 "./struct.h"
 int t ;
 
#line 14 "./struct.h"
 int d1 ;
 
#line 15 "./struct.h"
 int d2 ;
 
#line 16 "./struct.h"
 int c ;
 } ;/* exec sql end declare section */
#line 8 "outofscope.ec"


/* exec sql whenever sqlerror  stop ; */
#line 10 "outofscope.ec"


static void
get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
{
	/* exec sql begin declare section */
			  
		  
	
#line 16 "outofscope.ec"
 MYTYPE * myvar = malloc ( sizeof ( MYTYPE ) ) ;
 
#line 17 "outofscope.ec"
 MYNULLTYPE * mynullvar = malloc ( sizeof ( MYNULLTYPE ) ) ;
/* exec sql end declare section */
#line 18 "outofscope.ec"


	/* Test DECLARE ... SELECT ... INTO with pointers */

	ECPG_informix_set_var( 0, ( myvar ), __LINE__);\
 ECPG_informix_set_var( 1, ( mynullvar ), __LINE__);\
 ECPG_informix_reset_sqlca(); /* declare mycur cursor for select * from a1 */
#line 22 "outofscope.ec"


	if (sqlca.sqlcode != 0)
		exit(1);

	*myvar0 = myvar;
	*mynullvar0 = mynullvar;
}

static void
open_cur1(void)
{
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
	ECPGt_int,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).id),(long)1,(long)1,sizeof(int), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).id),(long)1,(long)1,sizeof(int), 
	ECPGt_char,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).t),(long)64,(long)1,(64)*sizeof(char), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).t),(long)1,(long)1,sizeof(int), 
	ECPGt_double,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).d1),(long)1,(long)1,sizeof(double), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).d1),(long)1,(long)1,sizeof(int), 
	ECPGt_double,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).d2),(long)1,(long)1,sizeof(double), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).d2),(long)1,(long)1,sizeof(int), 
	ECPGt_char,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).c),(long)30,(long)1,(30)*sizeof(char), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 34 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 34 "outofscope.ec"


	if (sqlca.sqlcode != 0)
		exit(1);
}

static void
get_record1(void)
{
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
	ECPGt_int,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).id),(long)1,(long)1,sizeof(int), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).id),(long)1,(long)1,sizeof(int), 
	ECPGt_char,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).t),(long)64,(long)1,(64)*sizeof(char), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).t),(long)1,(long)1,sizeof(int), 
	ECPGt_double,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).d1),(long)1,(long)1,sizeof(double), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).d1),(long)1,(long)1,sizeof(int), 
	ECPGt_double,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).d2),(long)1,(long)1,sizeof(double), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).d2),(long)1,(long)1,sizeof(int), 
	ECPGt_char,&((*( MYTYPE  *)(ECPG_informix_get_var( 0))).c),(long)30,(long)1,(30)*sizeof(char), 
	ECPGt_int,&((*( MYNULLTYPE  *)(ECPG_informix_get_var( 1))).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 43 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 43 "outofscope.ec"


	if (sqlca.sqlcode != 0 && sqlca.sqlcode != SQLNOTFOUND)
		exit(1);
}

static void
close_cur1(void)
{
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
#line 52 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 52 "outofscope.ec"


	if (sqlca.sqlcode != 0)
		exit(1);
}

int
main (void)
{
	MYTYPE		*myvar;
	MYNULLTYPE	*mynullvar;

	char msg[128];

	ECPGdebug(1, stderr);

	{ ECPGconnect(__LINE__, 1, "test" , NULL, NULL , NULL, 0); 
#line 68 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 68 "outofscope.ec"



	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table a1 ( id serial primary key , t text , d1 numeric , d2 float8 , c character ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
#line 71 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 71 "outofscope.ec"


	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'a' , 1.0 , 2 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
#line 73 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 73 "outofscope.ec"

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , null , null , null , null )", ECPGt_EOIT, ECPGt_EORT);
#line 74 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 74 "outofscope.ec"

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , '\"a\"' , - 1.0 , 'nan' :: float8 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
#line 75 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 75 "outofscope.ec"

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'b' , 2.0 , 3 , 'b' )", ECPGt_EOIT, ECPGt_EORT);
#line 76 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 76 "outofscope.ec"


	{ ECPGtrans(__LINE__, NULL, "commit");
#line 78 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 78 "outofscope.ec"


	/* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */

	get_var1(&myvar, &mynullvar);
	open_cur1();

	while (1)
	{
		memset(myvar, 0, sizeof(MYTYPE));
		get_record1();
		if (sqlca.sqlcode == SQLNOTFOUND)
			break;
		printf("id=%d%s t='%s'%s d1=%lf%s d2=%lf%s c = '%s'%s\n",
			myvar->id, mynullvar->id ? " (NULL)" : "",
			myvar->t, mynullvar->t ? " (NULL)" : "",
			myvar->d1, mynullvar->d1 ? " (NULL)" : "",
			myvar->d2, mynullvar->d2 ? " (NULL)" : "",
			myvar->c, mynullvar->c ? " (NULL)" : "");
	}

	close_cur1();

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
#line 101 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 101 "outofscope.ec"


	{ ECPGtrans(__LINE__, NULL, "commit");
#line 103 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 103 "outofscope.ec"


	{ ECPGdisconnect(__LINE__, "ALL");
#line 105 "outofscope.ec"

if (sqlca.sqlcode < 0) exit (1);}
#line 105 "outofscope.ec"


	return (0);
}