Michael Meskes írta:
> On Fri, Jul 17, 2009 at 12:27:49PM +0200, Boszormenyi Zoltan wrote:
>   
>> one of our clients wants to port their application suite
>> from Informix to PostgreSQL, they use constructs like
>>
>> SELECT * INTO :tablerec FROM table ...
>>
>> where "tablerec" mirrors the table fields in a C struct.
>>     
>
> Well, this was supposed to work.
>
>   
>> Currently ECPG dumps core on this, more exactly aborts on it
>> in ecpg_type_name().
>>     
>
> Could you please send an example where it dumps core?
>   

Attached is the short example I can reproduce with.
The version I used was final PostgreSQL 8.4.0, without our
extensions posted already. I added an indication to ecpg_type_name():

[z...@db00 ecpg-test]$ ecpg -C INFORMIX test28.pgc
ecpg_type_name: unhandled type 22
Félbeszakítva (core dumped)

Type 22 is exactly ECPGt_struct. gdb cannot get the passed value:

[z...@db00 ecpg-test]$ gdb ~/pgc84pre/bin/ecpg core.850
...
#0  0x0000003994032215 in raise (sig=<value optimized out>) at
../nptl/sysdeps/unix/sysv/linux/raise.c:64
64      return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
(gdb) bt
#0  0x0000003994032215 in raise (sig=<value optimized out>) at
../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x0000003994033d83 in abort () at abort.c:88
#2  0x0000000000423d65 in ecpg_type_name (typ=<value optimized out>) at
typename.c:65
#3  0x0000000000402742 in adjust_informix (list=0x1e74560) at preproc.y:272
#4  0x0000000000406ca7 in base_yyparse () at preproc.y:6581
#5  0x0000000000422b22 in main (argc=4, argv=0x7fff24b40aa8) at ecpg.c:456

test28.pgc contains this, ECPG aborts:

EXEC SQL DECLARE mycur CURSOR FOR SELECT * INTO :myvar FROM a1 WHERE id = 1;
EXEC SQL FETCH FROM mycur;

But you are right about the "supposed to work" part,
if I modify it the way below, it works:

EXEC SQL DECLARE mycur CURSOR FOR SELECT * FROM a1 WHERE id = 1;
EXEC SQL FETCH FROM mycur INTO :myvar;

Thanks,
Zoltán Böszörményi

> Michael
>   


-- 
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/

struct mytype {
	int	id;
	char	t[64];
	dec_t	d1;
	double	d2;
	char	c[30];
};
typedef struct mytype MYTYPE;
/*
 * Test DECLARE ... SELECT ... INTO ...
 * with "string"
 */

#include <stdio.h>
#include <stdlib.h>

EXEC SQL DEFINE MYDB1 zozo;
EXEC SQL DEFINE MYUSER1 zozo;

EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL include test28.h;
EXEC SQL END DECLARE SECTION;

int main(int argc, char **argv) {
        EXEC SQL BEGIN DECLARE SECTION;
        MYTYPE          myvar;
        EXEC SQL END DECLARE SECTION;

        EXEC SQL WHENEVER SQLWARNING SQLPRINT;
        EXEC SQL WHENEVER SQLERROR SQLPRINT;

        EXEC SQL connect to MYDB1 USER MYUSER1;
        if (sqlca.sqlcode)
        {
                printf ("connect error = %ld\n", sqlca.sqlcode);
                exit (sqlca.sqlcode);
        }

        EXEC SQL DECLARE mycur CURSOR FOR SELECT * INTO :myvar FROM a1 WHERE id 
= 1;
        EXEC SQL OPEN mycur;

        EXEC SQL WHENEVER NOT FOUND GOTO out;

        EXEC SQL FETCH FROM mycur;

        printf("c = '%s'\n", myvar.c);

out:
        EXEC SQL CLOSE mycur;

        EXEC SQL DISCONNECT;

        return 0;
}
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to