pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: CN <cnliou9@fastmail.fm>
To: pgsql-interfaces@postgresql.org
Subject: Re: Libpq: PQunescapeBytea
Date: Fri, 23 Mar 2007 21:11:17 +0800
Message-ID: <1174655477.29683.1181005343@webmail.messagingengine.com> (raw)

On Thu, 22 Mar 2007 17:23:01 +0100, "Daniel Verite"
<daniel@manitou-mail.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




view thread (2+ messages)

Message-ID: <1174655477.29683.1181005343@webmail.messagingengine.com>
Permalink:  ../1174655477.29683.1181005343@webmail.messagingengine.com/
Also on:    postgresql.org/message-id/1174655477.29683.1181005343@webmail.messagingengine.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: cnliou9@fastmail.fm
  Subject: Re: Libpq: PQunescapeBytea
  In-Reply-To: <1174655477.29683.1181005343@webmail.messagingengine.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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