Thread: embedded sql pointer to structure question
Hi, I have an application using structures say typedef struct { int id; char value[40]; } MYREC; When passing a record to a function insert_record( MYREC *pmyrec) how to deal with the sql-statement regarding the fields of the struct ? When doing this (TESTPROGRAM) : exec sql whenever sqlerror sqlprint; exec sql include sqlca; exec sql type MYREC is struct { int id; char value; } ; int main() { MYREC mr; mr.id = 10; strcpy(mr.value, "testval"); ... Exec sql begin declare section; MYREC *pmr = &mr; exec sql end declare section; EXEC SQL INSERT INTO test VALUES(:pmr->id, :pmr->value); ... } I get the message : ERROR: The variable id is not declared -- Feite Brekeveld feite.brekeveld@osiris-it.nl
On Fri, Mar 16, 2001 at 12:58:06PM +0100, Feite Brekeveld wrote: > ... > Exec sql begin declare section; > MYREC *pmr = &mr; > > exec sql end declare section; > ... > I get the message : ERROR: The variable id is not declared > ... Yes, this is a known limintation. It's even listed in the TODO file. For ECPG to be able to understand your variable it has to know the definition of the struct. Since it is not listed in your declare section it cannot learn the details and thus won't be able to parse the construct. Please try: exec sql begin declare section; struct { int id; char value[40]; } *pmr; exec sql end declare section; This should work. But be sure to use the latest CVS version as there was a small bug in this bug. I'm actually committing the fix right now. Michael -- Michael Meskes Michael@Fam-Meskes.De Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!
Michael Meskes wrote: > On Fri, Mar 16, 2001 at 12:58:06PM +0100, Feite Brekeveld wrote: > > ... > > Exec sql begin declare section; > > MYREC *pmr = &mr; > > > > exec sql end declare section; > > ... > > I get the message : ERROR: The variable id is not declared > > ... > > Yes, this is a known limintation. It's even listed in the TODO file. For > ECPG to be able to understand your variable it has to know the definition of > the struct. Since it is not listed in your declare section it cannot learn > the details and thus won't be able to parse the construct. > > Please try: > > exec sql begin declare section; > struct { > int id; > char value[40]; > } *pmr; > exec sql end declare section; If I do that ( tried that already ) I get an eror message: pmr is not a pointer at the point where I reference to it in the query: exec sql select ....bla bla ... where id = :pmr->id Is there more detailed documentation somewhere then whats going with the postgres distribution ? > > > This should work. But be sure to use the latest CVS version as there was a > small bug in this bug. I'm actually committing the fix right now. > > Michael > -- > Michael Meskes > Michael@Fam-Meskes.De > Go SF 49ers! Go Rhein Fire! > Use Debian GNU/Linux! Use PostgreSQL! -- Feite Brekeveld feite.brekeveld@osiris-it.nl http://www.osiris-it.nl
On Fri, Mar 16, 2001 at 09:51:20PM +0100, Feite Brekeveld wrote: > If I do that ( tried that already ) I get an eror message: > > pmr is not a pointer > > at the point where I reference to it in the query: > ... Please read my mail completely: > > This should work. But be sure to use the latest CVS version as there was a > > small bug in this bug. I'm actually committing the fix right now. Should read "bug in this part" of course. :-) Michael -- Michael Meskes Michael@Fam-Meskes.De Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!