Re: libpq-fe: PQgetvalue() ? - Mailing list pgsql-sql

From ljb
Subject Re: libpq-fe: PQgetvalue() ?
Date
Msg-id ckn6uj$g28$2@news.hub.org
Whole thread Raw
In response to libpq-fe: PQgetvalue() ?  (sad <sad@bankir.ru>)
List 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.

From the documentation:   The pointer returned by PQgetvalue points to storage that is part of the PGresult structure.
Oneshould not modify the data it points to, and one must explicitly copy the data into other storage if it is to be
usedpast the lifetime of the PGresult structure itself.
 

So no, you must not free your copy of the pointer returned by PQgetvalue,
and no, once you PQclear the result your pointer is not valid. You should


pgsql-sql by date:

Previous
From: "Fang Genjie"
Date:
Subject: the problem of createlang!
Next
From: Stephan Fiebrandt
Date:
Subject: need query advice