pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedECPG: FETCH ALL|n FROM cursor - Memory allocation?
2+ messages / 2 participants
[nested] [flat]
* ECPG: FETCH ALL|n FROM cursor - Memory allocation?
@ 2002-04-25 11:42 Lee Kindness <lkindness@csl.co.uk>
0 siblings, 1 reply; 2+ messages in thread
From: Lee Kindness @ 2002-04-25 11:42 UTC (permalink / raw)
To: pgsql-interfaces; +Cc: Lee Kindness <lkindness@csl.co.uk>; Mark Aves <maves@csl.co.uk>; Michael Meskes <meskes@postgresql.org>; PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Assuming the following fetch statement in embedded SQL/C:
EXEC SQL FETCH ALL IN selectFromTable_cur INTO
:array1,
:array2;
is memory automatically allocated (by experimentation I guess so)?
Should the input pointers be NULL initialised? How should the memory
be freed?
Assuming the following fetch statement:
while( 1 )
{
EXEC SQL FETCH 1000 IN selectFromTable_cur INTO
:array1,
:array2;
if( (sqlca.sqlcode < 0) || (sqlca.sqlcode != 0) )
break;
}
is memory automatically allocated (by experimentation I guess so)?
Should the input pointers be NULL initialised before each fetch, or
only before the first one? How should the memory be freed?
Any pointers to useful documentation?
Thanks, Lee Kindness.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: ECPG: FETCH ALL|n FROM cursor - Memory allocation?
@ 2002-04-25 13:07 Michael Meskes <meskes@postgresql.org>
parent: Lee Kindness <lkindness@csl.co.uk>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Meskes @ 2002-04-25 13:07 UTC (permalink / raw)
To: Lee Kindness <lkindness@csl.co.uk>; +Cc: pgsql-interfaces; Mark Aves <maves@csl.co.uk>; PostgreSQL Hackers <pgsql-hackers@postgresql.org>
On Thu, Apr 25, 2002 at 12:42:00PM +0100, Lee Kindness wrote:
> Assuming the following fetch statement in embedded SQL/C:
>
> EXEC SQL FETCH ALL IN selectFromTable_cur INTO
> :array1,
> :array2;
>
> is memory automatically allocated (by experimentation I guess so)?
Only if the pointers are NULL. If they have a value libecpg assumes that
this value points to enough memory to store all data.
> Should the input pointers be NULL initialised? How should the memory
> be freed?
A simple free() will do. You also can free all automatically
allocated memory from the most recent executed statement by calling
ECPGfree_auto_mem(). But this is not documented and will never be.
The correct way is to free(array1) and free(array2) while libecpg will
free the internal structures when the next statement is executed.
Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-04-25 13:07 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-25 11:42 ECPG: FETCH ALL|n FROM cursor - Memory allocation? Lee Kindness <lkindness@csl.co.uk>
2002-04-25 13:07 ` Michael Meskes <meskes@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox