pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
libpq-fe: PQgetvalue() ?
4+ messages / 4 participants
[nested] [flat]

* libpq-fe: PQgetvalue() ?
@ 2004-10-14 12:34  sad <sad@bankir.ru>
  0 siblings, 2 replies; 4+ messages in thread

From: sad @ 2004-10-14 12:34 UTC (permalink / raw)
  To: pgsql-sql

hi

does PQgetvalue() allocate memory rof its result, it returns ?
the answer will help me in problem:
should i free some cstring_variable if
{ cstring_variable=PQgetvalue(pgresult_variable,0,0); }
and could i PQclear(pgresult_varible) while cstring_varible is in use.

thnx




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: libpq-fe: PQgetvalue() ?
@ 2004-10-15 00:51  ljb <ljb220@mindspring.com>
  parent: sad <sad@bankir.ru>
  1 sibling, 0 replies; 4+ messages in thread

From: ljb @ 2004-10-15 00:51 UTC (permalink / raw)
  To: pgsql-sql

sad@bankir.ru wrote:
> hi
>
> does PQgetvalue() allocate memory rof its result, it returns ?
> the answer will help me in problem:
> should i free some cstring_variable if
> { cstring_variable=PQgetvalue(pgresult_variable,0,0); }
> and could i PQclear(pgresult_varible) while cstring_varible is in use.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: libpq-fe: PQgetvalue() ?
@ 2004-10-15 08:57  Christoph Haller <ch@rodos.fzk.de>
  parent: sad <sad@bankir.ru>
  1 sibling, 1 reply; 4+ messages in thread

From: Christoph Haller @ 2004-10-15 08:57 UTC (permalink / raw)
  To: sad <sad@bankir.ru>; +Cc: pgsql-sql

AFAIK it does allocate memory.
You cannot PQclear(pgresult_varible) while cstring_varible is in use.
You do not need to free cstring_variable, PQclear(pgresult_varible) will do.
I personally prefer to allocate local memory, "strcpy" PQgetvalue,
and then PQclear. But that's a matter of taste, I suppose.

Regards, Christoph


sad wrote:

> hi
>
> does PQgetvalue() allocate memory rof its result, it returns ?
> the answer will help me in problem:
> should i free some cstring_variable if
> { cstring_variable=PQgetvalue(pgresult_variable,0,0); }
> and could i PQclear(pgresult_varible) while cstring_varible is in use.
>
> thnx
>




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: libpq-fe: PQgetvalue() ?
@ 2004-10-15 14:21  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2004-10-15 14:21 UTC (permalink / raw)
  To: Christoph Haller <ch@rodos.fzk.de>; +Cc: sad <sad@bankir.ru>; pgsql-sql

Christoph Haller <ch@rodos.fzk.de> writes:
> You cannot PQclear(pgresult_varible) while cstring_varible is in use.
> You do not need to free cstring_variable, PQclear(pgresult_varible) will do.
> I personally prefer to allocate local memory, "strcpy" PQgetvalue,
> and then PQclear. But that's a matter of taste, I suppose.

That is surely overkill.

PQgetvalue doesn't allocate new memory for its result.  The docs are
reasonably clear, I thought:

     The pointer returned by PQgetvalue points to storage that is part
     of the PGresult structure. One should not modify the data it points
     to, and one must explicitly copy the data into other storage if it
     is to be used past the lifetime of the PGresult structure itself.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2004-10-15 14:21 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-14 12:34 libpq-fe: PQgetvalue() ? sad <sad@bankir.ru>
2004-10-15 00:51 ` ljb <ljb220@mindspring.com>
2004-10-15 08:57 ` Christoph Haller <ch@rodos.fzk.de>
2004-10-15 14:21   ` Tom Lane <tgl@sss.pgh.pa.us>

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