Fetching fields of a cursor into a struct, with ECPG

From: Antonio Sergio de Mello e Souza <asergioz(at)bol(dot)com(dot)br>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Fetching fields of a cursor into a struct, with ECPG
Date: 2001-10-26 16:21:21
Message-ID: 3BD98D81.8000603@bol.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi all,

I've been using ECPG, and I need to fetch the fields of a cursor into a
struct like this:

16 EXEC SQL BEGIN DECLARE SECTION;
17 struct TST_t {
18 char key[16];
19 double num;
20 } tst;
21 EXEC SQL END DECLARE SECTION;

When I use a FETCH statement like that on line 42

34 EXEC SQL DECLARE CTST_1 CURSOR FOR
35 SELECT KEY, NUM
36 FROM TABLE;
...
39
40 do
41 {
42 EXEC SQL FETCH CTST_1 INTO :tst.key, :tst.num;

ECPG generates this code, that compiles and runs correctly

138 { ECPGdo(__LINE__, NULL, "declare CTST_1 cursor for select KEY , NUM fr
om TABLE ", ECPGt_EOIT, ECPGt_EORT);
139 #line 37 "tstecpgC.ec"
...
145 do
146 {
147 { ECPGdo(__LINE__, NULL, "fetch CTST_1", ECPGt_EOIT,
148 ECPGt_char,(tst.key),16L,1L,16*sizeof(char),
149 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
150 ECPGt_double,&(tst.num),1L,1L,sizeof(double),
151 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
152 #line 41 "tstecpgC.ec"

However, when I use that FETCH statement on line 42

34 EXEC SQL DECLARE CTST_1 CURSOR FOR
35 SELECT KEY, NUM
36 FROM TABLE;
...
39
40 do
41 {
42 EXEC SQL FETCH CTST_1 INTO :tst;

ECPG generates the code below, that compiles correctly but, when ran,
receives this error:
SQLCODE = -200; Unsupported type double in line 41

138 { ECPGdo(__LINE__, NULL, "declare CTST_1 cursor for select KEY , NUM fr
om TABLE ", ECPGt_EOIT, ECPGt_EORT);
139 #line 37 "tstecpgC.ec"
...
145 do
146 {
147 { ECPGdo(__LINE__, NULL, "fetch CTST_1", ECPGt_EOIT,
148 ECPGt_char,(tst.key),16L,1L,16*sizeof(char),
149 ECPGt_double,&(tst.num),1L,1L,sizeof(double), ECPGt_EORT);
150 #line 41 "tstecpgC.ec"

Please, is there a way to fetch the fields of a cursor into a struct
without citing
each member individually? I looked up in the documentation and in the
file preproc.y
but couldn't figure it out.

I'm running PostgreSQL 7.1.2, on Linux 2.2.16, compiled with options:
--prefix=/usr/local/pgsql --enable-locale --enable-multibyte

Regards,

Antonio Sergio

Browse pgsql-interfaces by date

  From Date Subject
Next Message Egidijus Kizlaitis 2001-10-27 13:48:49 problems with libpq on windows
Previous Message Christof Petig 2001-10-26 07:49:47 Re: ECPG: Automatic Storage allocation for NULL-pointing output