pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: William West <wwest@csc.com>
To: pgsql-interfaces@postgresql.org
Subject: ECGP - varchar in struct?
Date: Fri, 26 Jul 2002 21:38:25 -0400
Message-ID: <OFA1413DBF.B48A0524-ON85256C03.00014BAD@com> (raw)

I looked at comp.databases.postgresql.questions
and posted a brief form of this question there.

I am porting an existing Oracle/ PRO-C Application
over to PostgreSQL 7.2.1 (ecpg 2.9.0).

This application takes advantage of the fact that
PRO-C lets you use 'varchar' as part of 'struct'
definitions by re-writing 'varchar' during INCLUDE
or DECLARE processing either one. This application
can (and presently does) make a lot of use of:

struct rowdef {
  ... /* Column */
  varchar nameOFcolumn[maxlen] ;
  ... /* Column */
};

to define an interface buffer. PRO-C will re-write
this, during EXEC SQL INCLUDE processing, as:

struct rowdef {
... /* Column */
struct {int len;  char arr[maxlen];} nameOFcolumn;
... /* Column */
};

This makes it possible to easily declare an I/O buffer
that can hold many rows:

EXEC SQL BEGIN DECLARE SECTION;
    struct rowdef ManyRows[25];
EXEC SQL END DECLARE SECTION;

and code can easily refer to members of this buffer:

/* Length column instance 7 */
ManyRows [7].nameOFcolumn.len;

/* Address of column instance 7 */
ManyRows [7].nameOFcolumn.arr;

or send them to other compile units:

 foo (ManyRows + 7);

can run 'foo' on row 7 without 'foo' needing to be
able to see the ManyRows DECLARE. The 'foo' compile
unit only needs the INCLUDE to provide the 'rowdef'
struct layout, since INCLUDE processing takes care
of the C re-write that a varchar always needs.

====

It would appear that ecpg will only re-write a
varchar if it is found in a DECLARE statement,
because the varchar gets past the ecpg preprocessor's
INCLUDE as-is ... and, of course, the real C compiler
does not know what a 'varchar' is, so it complains.

As a PostgreSQL 'newbie', I am not sure if it is more
work to fix ecpg or to re-write how the application
does things. I see it is a 'yacc' unit that handles the
re-writing that ecpg now does, but I do not know
'yacc-ese' and do not know what else would be involved
to fix ecpg to work like PRO-C?

- Did I miss something here?
- Any insights/ advice from the gurus?
- Would it be a really big deal to support
  varchar re-writes during INCLUDE and not
  just during DECLARE?




view thread (8+ messages)  latest in thread

Message-ID: <OFA1413DBF.B48A0524-ON85256C03.00014BAD@com>
Permalink:  ../OFA1413DBF.B48A0524-ON85256C03.00014BAD@com/
Also on:    postgresql.org/message-id/OFA1413DBF.B48A0524-ON85256C03.00014BAD@com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: wwest@csc.com
  Subject: Re: ECGP - varchar in struct?
  In-Reply-To: <OFA1413DBF.B48A0524-ON85256C03.00014BAD@com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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