Thread: ecpg & host variables

ecpg & host variables

From
Daniel Kelley
Date:
hi-

i'm looking to convert a pro*c application to something
postgresql-based.  i've just started to experiment with ecpg, and have
been pleasantly surprised that large parts of out existing code will be
useable without too much alteration.

the problems that i've run into all involve variable declarations.  we
have a large number of complex structures that map in-house
datatypes.  with oracle, we could do something like this:

--------------------------------------------------------
typedef struct {       int               id;       char              name[30];       char          dsc[1000];
} rec_t;

rec_t        r;

EXEC SQL SELECT         id,         name,         dsc         INTO         :r.id,         :r.name,         :r.dsc
 FROM table         WHERE id = :r.id;
 
--------------------------------------------------------

to make this code work with ecpg, i've made the following changes:

--------------------------------------------------------
EXEC SQL BEGIN DECLARE SECTION;
typedef struct {       int               id;       char              name[30];       char              dsc[1000];
} rec_t;

rec_t           r;
EXEC SQL END DECLARE SECTION;
--------------------------------------------------------

which yields the following error from ecpg:

postgres.pgc:15: ERROR: invalid datatype 'typedef'

is there are facility that i might be missing that would allow me to use
our existing structures as host variables w/ postgres embedded sql?  or am
i better off just skipping ecpg and coding directly with libpq?

thanks in advance for any insight you can offer.

dan




Re: ecpg & host variables

From
Tom Lane
Date:
Daniel Kelley <dkelley@otec.com> writes:
> ... which yields the following error from ecpg:
> postgres.pgc:15: ERROR: invalid datatype 'typedef'

I believe ecpg was just recently fixed to support typedefs.  You might
try using the ecpg from a recent snapshot.  (AFAIK it should be stable
enough for production use, though I'd not recommend using anything else
from development tip ...)
        regards, tom lane


Re: ecpg & host variables

From
Michael Meskes
Date:
On Fri, Jul 19, 2002 at 05:02:53PM -0400, Daniel Kelley wrote:
> EXEC SQL BEGIN DECLARE SECTION;
> typedef struct {
>         int               id;
>         char              name[30];
>         char              dsc[1000];
> } rec_t;
> 
> rec_t           r;
> EXEC SQL END DECLARE SECTION;

Actually this will not work, but you can do the following:

EXEC SQL BEGIN DECLARE SECTION; 
struct {        int               id;        char              name[30];        char              dsc[1000];
} r;
EXEC SQL END DECLARE SECTION;

or use the EXEC SQL TYPE command to do a typedef so ecpg knows about it:

EXEC SQL TYPE rec_r is struct {        int               id;        char              name[30];        char
dsc[1000];
 
}

> is there are facility that i might be missing that would allow me to use
> our existing structures as host variables w/ postgres embedded sql?  or am
> i better off just skipping ecpg and coding directly with libpq?

That will be much more work. ecpg was modelled in a way that pro*c apps
should compile without much of a problem.

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!