Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id DDBB99FBCEF for ; Fri, 23 Mar 2007 10:11:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 65423-08 for ; Fri, 23 Mar 2007 10:11:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from out5.smtp.messagingengine.com (out5.smtp.messagingengine.com [66.111.4.29]) by postgresql.org (Postfix) with ESMTP id 80BE89FBC50 for ; Fri, 23 Mar 2007 10:11:19 -0300 (ADT) Received: from compute1.internal (unknown [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 1382520BEBF for ; Fri, 23 Mar 2007 09:11:18 -0400 (EDT) Received: from web2.messagingengine.com ([10.202.2.211]) by compute1.internal (MEProxy); Fri, 23 Mar 2007 09:11:18 -0400 Received: by web2.messagingengine.com (Postfix, from userid 99) id E98237023; Fri, 23 Mar 2007 09:11:17 -0400 (EDT) Message-Id: <1174655477.29683.1181005343@webmail.messagingengine.com> X-Sasl-Enc: ZCQYcwVnsNNBrn29EcwoGNSFoh+53wKMXHPw3qfergzo 1174655477 From: "CN" To: pgsql-interfaces@postgresql.org Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="Big5" MIME-Version: 1.0 X-Mailer: MessagingEngine.com Webmail Interface References: 20070322172202.17336 Subject: Re: Libpq: PQunescapeBytea In-Reply-To: 20070322172202.17336 Date: Fri, 23 Mar 2007 21:11:17 +0800 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.899 tagged_above=0 required=5 tests=AWL, BAYES_05, RAZOR2_CF_RANGE_51_100, RAZOR2_CF_RANGE_E8_51_100, RAZOR2_CHECK X-Spam-Level: * X-Archive-Number: 200703/32 X-Sequence-Number: 6473 On Thu, 22 Mar 2007 17:23:01 +0100, "Daniel Verite" 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