ECGP - varchar in struct?

From: "William West" <wwest(at)csc(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: ECGP - varchar in struct?
Date: 2002-07-27 01:38:25
Message-ID: OFA1413DBF.B48A0524-ON85256C03.00014BAD@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

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?

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Denis Chavez 2002-07-28 04:04:53 Kerberos authentication with libpgtcl
Previous Message kklein 2002-07-25 23:44:57 Re: dbf2pg, visual foxpro and other nonsense