From: | Boszormenyi Zoltan <zb(at)cybertec(dot)at> |
---|---|
To: | Michael Meskes <meskes(at)postgresql(dot)org> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at> |
Subject: | Re: ECPG support for struct in INTO list |
Date: | 2009-08-05 09:08:26 |
Message-ID: | 4A794C0A.6020500@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Michael Meskes írta:
> On Fri, Jul 31, 2009 at 11:42:33AM +0200, Boszormenyi Zoltan wrote:
>
>> made me look around more. Find the attached patch I came up with.
>> Now my previous test code works and produces similar C code
>> as without "-C INFORMIX". Can it be this simple?
>>
>
> Unfortunately it is not.
>
>
>> Can you see anything wrong with this approach?
>>
>
> Yes, please look at the slightly changed test version that is attached to this email.
>
I have looked at it. The code seems to be invalid.
get_var(void)
{
EXEC SQL BEGIN DECLARE SECTION;
MYTYPE myvar;
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE mycur CURSOR FOR SELECT * INTO :myvar FROM a1 WHERE id = 1;
}
"myvar" is lost as soon as the function returns
and is not visible to calling functions.
I tried to compile your code (with my previous "fix"
in place, so at least :myvar is processed and C code is output):
$ make test28
ecpg -C INFORMIX test28.pgc
cc -g -O2 -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing
-fwrapv -g -I/home/zozo/pgc84pre/include
-I/home/zozo/pgc84pre/include/postgresql/internal -c -o test28.o test28.c
test28.pgc:15: warning: return type defaults to ‘int’
test28.pgc:14: warning: no previous prototype for ‘get_var’
test28.pgc: In function ‘get_var’:
test28.pgc:17: warning: unused variable ‘myvar’
test28.pgc: In function ‘main’:
test28.pgc:45: error: ‘myvar’ undeclared (first use in this function)
test28.pgc:45: error: (Each undeclared identifier is reported only once
test28.pgc:45: error: for each function it appears in.)
make: *** [test28.o] Error 1
rm test28.c
Line 45 in the modified code sent by you is:
printf("c = '%s'\n", myvar.c);
and the compiler correctly complains.
> If you use e.g. int instead of MYTYPE, it works nicely, but not with MYTYPE.
>
I modified getvar this way:
get_var(void)
{
EXEC SQL BEGIN DECLARE SECTION;
int myid;
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE mycur CURSOR FOR SELECT id INTO :myid FROM a1 WHERE id
= 1;
}
And the preprocessed code via "ecpg -C INFORMIX" is:
get_var(void)
{
/* exec sql begin declare section */
#line 17 "test28.pgc"
int myid ;
/* exec sql end declare section */
#line 18 "test28.pgc"
ECPG_informix_set_var( 0, &( myid ), __LINE__);\
/* declare mycur cursor for select id from a1 where id = 1 */
#line 20 "test28.pgc"
}
Some systems (stack-protector extensions to GCC, etc)
make the code segfault immediately as soon as the first
FETCH statement tries to touch the lost memory area.
Just because ECPG does some tricks with ECPG_informix_set_var()
and ECPG_informix_get_var() converting variable reference
to runtime pointer values, the code wouldn't get magically valid.
> Please see the comments in adjust_informix to see what this function is
> supposed to do.
>
I did and I don't understand. I think it's just a bug
in ESQL/C to accept such constructs.
> Michael
>
Best regards,
Zoltán Böszörményi
--
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/
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 2009-08-05 09:24:17 | Re: ECPG support for struct in INTO list |
Previous Message | Michael Meskes | 2009-08-05 08:42:56 | Re: ECPG support for struct in INTO list |