Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DF5F99FB324 for ; Thu, 8 Feb 2007 08:12:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 30904-08 for ; Thu, 8 Feb 2007 08:12:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id C17F39FB323 for ; Thu, 8 Feb 2007 08:12:49 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from vsxkg005.ocn.ad.jp (vsxkg005.ocn.ad.jp [211.129.17.144]) by svr4.postgresql.org (Postfix) with ESMTP id 97BF15AF03D for ; Thu, 8 Feb 2007 12:12:48 +0000 (GMT) Received: from sgc002.ocn.ne.jp (ov-orv-hkg002.ocn.ad.jp [211.129.17.155]) by vsxkg005.ocn.ad.jp (Postfix) with SMTP id 97F74501 for ; Thu, 8 Feb 2007 21:12:44 +0900 (JST) Received: from [192.168.21.64] (dsl-51-161.dsl.netsource.ie [213.79.51.161]) by sgc002.ocn.ne.jp (Postfix) with ESMTP id B1D0E954 for ; Thu, 8 Feb 2007 21:12:42 +0900 (JST) From: Vincent de Phily Organization: BlueMetrix To: pgsql-php@postgresql.org Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux Date: Thu, 8 Feb 2007 12:12:43 +0000 User-Agent: KMail/1.9.6 References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com> <302670f20702070658vb0913e2xa51d153ddbe5b34d@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200702081212.43200.vdephily@bluemetrix.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/14 X-Sequence-Number: 3697 On Thursday 08 February 2007, ljb wrote: > gwchamb@gmail.com wrote: > > Vincent... > > > >> This would be a problem related to php, not postgres. I'm handling > >> binary data in parameterized and COPY queries just fine with c++. > > > > I'm not ruling-out PHP, but I've seen claims of pg_[un]escape_bytea > > being only wrappers to the Pg functions. > > That is correct, the PHP function relies on the PostgreSQL library to do > the work. But the problem of using a parameterized query with bytea data > is specific to PHP. PostgreSQL allows you to either escape the bytea > data for use as a text-mode parameter, or pass it 'raw' as a binary-mode > parameter. I don't know a good way to do the first in PHP, and the PHP > PostgreSQL interface doesn't support the second at all. This sparked my interest, so I checked the libpq docs (http://www.postgresql.org/docs/8.2/interactive/libpq-exec.html) and wrote some php tests. The postgres doc say that the escape functions should only be used "for Inclusion in SQL Commands", and that "it is not necessary nor correct to do escaping when a data value is passed as a separate parameter in PQexecParams". But when I try to pass the raw data using pg_query_params(), postgres complains about UTF8 (on a supposedly bytea field). Makes you wonder which postgres function does pg_query_params() really wrap around... I reallize I went all this way to just re-discover what has been said in this thread, but if I needed the extra research, maybe other will find it insightfull. -- Vincent de Phily