pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ecpg & host variables
3+ messages / 3 participants
[nested] [flat]

* ecpg & host variables
@ 2002-07-19 21:02 Daniel Kelley <dkelley@otec.com>
  2002-07-19 21:24 ` Re: ecpg & host variables Tom Lane <tgl@sss.pgh.pa.us>
  2002-07-20 11:45 ` Re: ecpg & host variables Michael Meskes <meskes@postgresql.org>
  0 siblings, 2 replies; 3+ messages in thread

From: Daniel Kelley @ 2002-07-19 21:02 UTC (permalink / raw)
  To: pgsql-interfaces


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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: ecpg & host variables
  2002-07-19 21:02 ecpg & host variables Daniel Kelley <dkelley@otec.com>
@ 2002-07-19 21:24 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2002-07-19 21:24 UTC (permalink / raw)
  To: Daniel Kelley <dkelley@otec.com>; +Cc: pgsql-interfaces

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: ecpg & host variables
  2002-07-19 21:02 ecpg & host variables Daniel Kelley <dkelley@otec.com>
@ 2002-07-20 11:45 ` Michael Meskes <meskes@postgresql.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Meskes @ 2002-07-20 11:45 UTC (permalink / raw)
  To: Daniel Kelley <dkelley@otec.com>; +Cc: pgsql-interfaces

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!



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-07-20 11:45 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-19 21:02 ecpg & host variables Daniel Kelley <dkelley@otec.com>
2002-07-19 21:24 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-07-20 11:45 ` Michael Meskes <meskes@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox