Re: CommitFest 2009-09, two weeks on - Mailing list pgsql-hackers

From Boszormenyi Zoltan
Subject Re: CommitFest 2009-09, two weeks on
Date
Msg-id 4AC60DC8.20809@cybertec.at
Whole thread Raw
In response to Re: CommitFest 2009-09, two weeks on  (Michael Meskes <meskes@postgresql.org>)
List pgsql-hackers
Michael Meskes írta:
> On Thu, Oct 01, 2009 at 09:05:55PM +0200, Boszormenyi Zoltan wrote:
>
>> Yes, but technical problems and solutions do. ECPG claims
>> to be ESQL/C compatible, but at places it's only half compatible.
>>
>
> Where does it claim to be fully compatible?
>

I didn't say it claims to be fully compatible, but it's
a "hint" that "ecpg -C INFORMIX[_SE]" exists. :-)

>> This comment is misleading and reflects quite a narrow POV.
>> Not only OPEN and DECLARE may be out of scope,
>> but FETCH and CLOSE as well. The reason why ESQL/C
>> allows this construct is that this ultimately allows using
>> embedded SQL in event-driven code in a straightforward way.
>> For this purpose, native ECPG code is not usable currently,
>> or you need programming tricks, like tracking whether the
>> cursor is open and protecting DECLARE and OPEN under
>> some conditional branch to avoid double open, etc. A straight
>> DECLARE, OPEN, FETCH(s) and CLOSE series in
>> the same function is only good for batch programming.
>>
>
> Examples?
>

I took my outofscope.pgc example from our "out of
scope" patch and shortened it. Compare the ecpg-native and
compat outputs and the esql output of the same file. The ecpg
outputs are generated with 8.4.1 plus out patches added, the
native output differs only from 8.3.7's ecpg in the amount of
whitespaces emitted between literals. The get_record1()
function can be called from a button-handler, e.g. when pressing
PgDn, or similar... No tricks needed, straightforward code.

Best regards,
Zoltán Böszörményi

--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

exec sql begin declare section;
exec sql include struct.h;
exec sql end declare section;

exec sql whenever sqlerror stop;

static void
get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
{
    exec sql begin declare section;
    MYTYPE        *myvar = malloc(sizeof(MYTYPE));
    MYNULLTYPE    *mynullvar = malloc(sizeof(MYNULLTYPE));
    exec sql end declare section;

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

    exec sql declare mycur cursor for select * INTO :myvar :mynullvar from a1;

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

    *myvar0 = myvar;
    *mynullvar0 = mynullvar;
}

static void
open_cur1(void)
{
    exec sql open mycur;

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

static void
get_record1(void)
{
    exec sql fetch mycur;

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

static void
close_cur1(void)
{
    exec sql close mycur;

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

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

    char msg[128];

    ECPGdebug(1, stderr);

    exec sql connect to "test";


    exec sql create table a1(id serial primary key, t text, d1 numeric, d2 float8, c character(10));

    exec sql insert into a1(id, t, d1, d2, c) values (default, 'a', 1.0, 2, 'a');
    exec sql insert into a1(id, t, d1, d2, c) values (default, null, null, null, null);
    exec sql insert into a1(id, t, d1, d2, c) values (default, '"a"', -1.0, 'nan'::float8, 'a');
    exec sql insert into a1(id, t, d1, d2, c) values (default, 'b', 2.0, 3, 'b');

    exec sql commit;

    /* 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();

    exec sql drop table a1;

    exec sql commit;

    exec sql disconnect all;

    return (0);
}

struct mytype {
    int    id;
    char    t[64];
    double    d1; /* dec_t */
    double    d2;
    char    c[30];
};
typedef struct mytype MYTYPE;

struct mynulltype {
    int    id;
    int    t;
    int    d1;
    int    d2;
    int    c;
};
typedef struct mynulltype MYNULLTYPE;
/* Processed by ecpg (4.5.0) */
/* These include files are added by the preprocessor */
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.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 */

    /* 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__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT,
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__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT, 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__, 0, 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__, 0, "test" , NULL, NULL , NULL, 0);
#line 68 "outofscope.ec"

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



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

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


    { ECPGdo(__LINE__, 0, 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__, 0, 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__, 0, 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__, 0, 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__, 0, 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);
}
/* 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 ,
d2float8 , 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);
}
#include <stdlib.h>
#include <sqlhdr.h>
#include <sqliapi.h>
static const char _Cn1[] = "mycur";
#line 1 "outofscope.ec"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

/*
 * exec sql begin declare section;
 */
#line 6 "outofscope.ec"
/*
 * exec sql include struct.h;
 */
#line 7 "outofscope.ec"

#line 7 "outofscope.ec"
#line 127 "struct.h"
#line 1 "outofscope.ec"
struct mytype
  {
    int id;
      char t[64];
    double d1;
    double d2;
      char c[30];
  } ;
typedef struct mytype MYTYPE;
struct mynulltype
  {
    int id;
    int t;
    int d1;
    int d2;
    int c;
  } ;
typedef struct mynulltype MYNULLTYPE;
/*
 * exec sql end declare section;
 */
#line 8 "outofscope.ec"

#line 9 "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 15 "outofscope.ec"
#line 16 "outofscope.ec"
MYTYPE *myvar = malloc(sizeof(MYTYPE));
MYNULLTYPE *mynullvar = malloc(sizeof(MYNULLTYPE));
/*
 *     exec sql end declare section;
 */
#line 18 "outofscope.ec"


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

/*
 *     exec sql declare mycur cursor for select * INTO :myvar :mynullvar from a1;
 */
#line 22 "outofscope.ec"
  {
#line 22 "outofscope.ec"
  static const char *sqlcmdtxt[] =
#line 22 "outofscope.ec"
    {
#line 22 "outofscope.ec"
    "select * from a1",
    0
    };
#line 22 "outofscope.ec"
  static ifx_sqlvar_t _sqobind[] =
    {
      { 102, sizeof((myvar)->id), 0, 0, 0, 0, 102, sizeof((mynullvar)->id), 0, 0, 0, 0, 0, 0, 0, 0 },
      { 100, 64, 0, 0, 0, 0, 102, sizeof((mynullvar)->t), 0, 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof((myvar)->d1), 0, 0, 0, 0, 102, sizeof((mynullvar)->d1), 0, 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof((myvar)->d2), 0, 0, 0, 0, 102, sizeof((mynullvar)->d2), 0, 0, 0, 0, 0, 0, 0, 0 },
      { 100, 30, 0, 0, 0, 0, 102, sizeof((mynullvar)->c), 0, 0, 0, 0, 0, 0, 0, 0 },
#line 22 "outofscope.ec"
    };
  static ifx_sqlda_t _SD0 = { 5, _sqobind, {0}, 5, 0 };
#line 22 "outofscope.ec"
  _sqobind[0].sqldata = (char *) &(myvar)->id;
_sqobind[0].sqlidata = (char *) &(mynullvar)->id;
#line 22 "outofscope.ec"
  _sqobind[1].sqldata = (myvar)->t;
_sqobind[1].sqlidata = (char *) &(mynullvar)->t;
#line 22 "outofscope.ec"
  _sqobind[2].sqldata = (char *) &(myvar)->d1;
_sqobind[2].sqlidata = (char *) &(mynullvar)->d1;
#line 22 "outofscope.ec"
  _sqobind[3].sqldata = (char *) &(myvar)->d2;
_sqobind[3].sqlidata = (char *) &(mynullvar)->d2;
#line 22 "outofscope.ec"
  _sqobind[4].sqldata = (myvar)->c;
_sqobind[4].sqlidata = (char *) &(mynullvar)->c;
#line 22 "outofscope.ec"
sqli_curs_decl_stat(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 512), _Cn1, sqlcmdtxt, (ifx_sqlda_t *)0,
&_SD0,0, (ifx_literal_t *)0, (ifx_namelist_t *)0, 2, 0, 0); 
#line 22 "outofscope.ec"
  { if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 22 "outofscope.ec"
}

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

    *myvar0 = myvar;
    *mynullvar0 = mynullvar;
}

static void
open_cur1(void)
{
/*
 *     exec sql open mycur;
 */
#line 34 "outofscope.ec"
{
#line 34 "outofscope.ec"
sqli_curs_open(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768), (ifx_sqlda_t *)0, (char *)0, (struct value
*)0,0, 0); 
#line 34 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 34 "outofscope.ec"
}

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

static void
get_record1(void)
{
/*
 *     exec sql fetch mycur;
 */
#line 43 "outofscope.ec"
{
#line 43 "outofscope.ec"
static _FetchSpec _FS0 = { 0, 1, 0 };
sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768), (ifx_sqlda_t *)0, (ifx_sqlda_t *)0, (char
*)0,&_FS0); 
#line 43 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 43 "outofscope.ec"
}

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

static void
close_cur1(void)
{
/*
 *     exec sql close mycur;
 */
#line 52 "outofscope.ec"
{
#line 52 "outofscope.ec"
sqli_curs_close(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, _Cn1, 768));
#line 52 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); 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);

/*
 *     exec sql connect to "test";
 */
#line 68 "outofscope.ec"
{
#line 68 "outofscope.ec"
sqli_connect_open(ESQLINTVERSION, 0, "test", (char *)0, (ifx_conn_t *)0, 0);
#line 68 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 68 "outofscope.ec"
}


/*
 *     exec sql create table a1(id serial primary key, t text, d1 numeric, d2 float8, c character(10));
 */
#line 71 "outofscope.ec"
{
#line 71 "outofscope.ec"
static const char *sqlcmdtxt[] =
#line 71 "outofscope.ec"
{
#line 71 "outofscope.ec"
"create table a1 ( id serial primary key , t text , d1 numeric , d2 float8 , c character ( 10 ) )",
0
};
#line 71 "outofscope.ec"
static ifx_statement_t _SQ0 = {0};
#line 71 "outofscope.ec"
sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0,
(ifx_namelist_t*)0, (ifx_cursor_t *)0, -1, 0, 0); 
#line 71 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 71 "outofscope.ec"
}

/*
 *     exec sql insert into a1(id, t, d1, d2, c) values (default, 'a', 1.0, 2, 'a');
 */
#line 73 "outofscope.ec"
{
#line 73 "outofscope.ec"
static const char *sqlcmdtxt[] =
#line 73 "outofscope.ec"
{
#line 73 "outofscope.ec"
"insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'a' , 1.0 , 2 , 'a' )",
0
};
#line 73 "outofscope.ec"
static ifx_statement_t _SQ0 = {0};
#line 73 "outofscope.ec"
sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0,
(ifx_namelist_t*)0, (ifx_cursor_t *)0, 6, 0, 0); 
#line 73 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 73 "outofscope.ec"
}
/*
 *     exec sql insert into a1(id, t, d1, d2, c) values (default, null, null, null, null);
 */
#line 74 "outofscope.ec"
{
#line 74 "outofscope.ec"
static const char *sqlcmdtxt[] =
#line 74 "outofscope.ec"
{
#line 74 "outofscope.ec"
"insert into a1 ( id , t , d1 , d2 , c ) values ( default , null , null , null , null )",
0
};
#line 74 "outofscope.ec"
static ifx_statement_t _SQ0 = {0};
#line 74 "outofscope.ec"
sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0,
(ifx_namelist_t*)0, (ifx_cursor_t *)0, 6, 0, 0); 
#line 74 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 74 "outofscope.ec"
}
/*
 *     exec sql insert into a1(id, t, d1, d2, c) values (default, '"a"', -1.0, 'nan'::float8, 'a');
 */
#line 75 "outofscope.ec"
{
#line 75 "outofscope.ec"
static const char *sqlcmdtxt[] =
#line 75 "outofscope.ec"
{
#line 75 "outofscope.ec"
"insert into a1 ( id , t , d1 , d2 , c ) values ( default , '"a"' , - 1.0 , 'nan' :: float8 , 'a' )",
0
};
#line 75 "outofscope.ec"
static ifx_statement_t _SQ0 = {0};
#line 75 "outofscope.ec"
sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0,
(ifx_namelist_t*)0, (ifx_cursor_t *)0, 6, 0, 0); 
#line 75 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 75 "outofscope.ec"
}
/*
 *     exec sql insert into a1(id, t, d1, d2, c) values (default, 'b', 2.0, 3, 'b');
 */
#line 76 "outofscope.ec"
{
#line 76 "outofscope.ec"
static const char *sqlcmdtxt[] =
#line 76 "outofscope.ec"
{
#line 76 "outofscope.ec"
"insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'b' , 2.0 , 3 , 'b' )",
0
};
#line 76 "outofscope.ec"
static ifx_statement_t _SQ0 = {0};
#line 76 "outofscope.ec"
sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0,
(ifx_namelist_t*)0, (ifx_cursor_t *)0, 6, 0, 0); 
#line 76 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 76 "outofscope.ec"
}

/*
 *     exec sql commit;
 */
#line 78 "outofscope.ec"
{
#line 78 "outofscope.ec"
sqli_trans_commit();
#line 78 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); 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();

/*
 *     exec sql drop table a1;
 */
#line 101 "outofscope.ec"
{
#line 101 "outofscope.ec"
static const char *sqlcmdtxt[] =
#line 101 "outofscope.ec"
{
#line 101 "outofscope.ec"
"drop table a1",
0
};
#line 101 "outofscope.ec"
static ifx_statement_t _SQ0 = {0};
#line 101 "outofscope.ec"
sqli_stmt(ESQLINTVERSION, &_SQ0, sqlcmdtxt, 0, (ifx_sqlvar_t *)0, (struct value *)0, (ifx_literal_t *)0,
(ifx_namelist_t*)0, (ifx_cursor_t *)0, -1, 0, 0); 
#line 101 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 101 "outofscope.ec"
}

/*
 *     exec sql commit;
 */
#line 103 "outofscope.ec"
{
#line 103 "outofscope.ec"
sqli_trans_commit();
#line 103 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 103 "outofscope.ec"
}

/*
 *     exec sql disconnect all;
 */
#line 105 "outofscope.ec"
{
#line 105 "outofscope.ec"
sqli_connect_close(2, (char *)0, 0, 0);
#line 105 "outofscope.ec"
{ if (SQLCODE < 0) { sqli_stop_whenever(); exit(1);} }
#line 105 "outofscope.ec"
}

    return (0);
}

#line 108 "outofscope.ec"

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: commented out para in docs
Next
From: Caleb Welton
Date:
Subject: Re: CREATE OR REPLACE FUNCTION vs ownership