Re: Libpq: PQunescapeBytea

From: "CN" <cnliou9(at)fastmail(dot)fm>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Libpq: PQunescapeBytea
Date: 2007-03-23 13:11:17
Message-ID: 1174655477.29683.1181005343@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Thu, 22 Mar 2007 17:23:01 +0100, "Daniel Verite"
<daniel(at)manitou-mail(dot)org> said:
> CN wrote:
>
> > Question: Does it mean that there exist some functions being able to
> > retrieve bytea columns in "binary format"? My understanding of its
> > meaning is that these functions will automatically restore the data read
> > from database to their original unescaped binary strings and thus
> > PQescapeBytea needs not to be called. If it does, what are these
> > functions? PQgetvalue appears to be not one of them I think.
>
> There's no specific function but when you pass 1 to the
> 'resultFormat' parameter of PQexecParams(), its results are
> returned in binary format.
> Then PQgetvalue() will give you the address of the data and
> PQgetlength() its size. When this data is of type bytea, no
> conversion is required.

Thank you for the explanation!

I did more testings and noted more details not depicted in the document:

- If a text string is written by PQexecParams() with paramFormats set to
1 and PQexec() is called to retrieve the data, unescaping is not needed
to be applied to the value returned by PQgetvalue().

- If a binary string is written by PQexecParams() with paramFormats set
to 1 and PQexec() is called to retrieve the data, it is essential to
call PQescapeBytea to unescape the value returned by PQgetvalue() in
order to restore it to the original binary string.

- If a binary string is written by PQexecParams() with paramFormats set
to 1 and PQexecParams() is called (with resultFormat set to 1) to
retrieve the data, unescaping is not needed to be applied to the value
returned by PQgetvalue().

Regards,
CN

--
http://www.fastmail.fm - The professional email service

Browse pgsql-interfaces by date

  From Date Subject
Next Message Sean Davis 2007-03-25 17:06:29 ODBC for Mac OS
Previous Message CN 2007-03-22 13:36:28 Libpq: PQunescapeBytea