Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 925DD9FB1BF for ; Sat, 3 Feb 2007 00:09:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 72509-09 for ; Sat, 3 Feb 2007 00:09:10 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 289469F9B3A for ; Sat, 3 Feb 2007 00:09:09 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so835618ugf for ; Fri, 02 Feb 2007 20:09:09 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZymRnBnlFFWCmON3IOApKq7xavhNE/V5Rgq/yVDR6z3BFZhAe/jraMUvSQwzZ8XW7ew5JT4x91K+wjBHV/AdYwKEx3J15nzxNbZs26gctqg9gP2dbuFWOu6UiLSXKgLPmqB4DHRT6acxGwT2lhI10E4M36G3lbHPTDCLQrFzVN8= Received: by 10.78.203.13 with SMTP id a13mr890138hug.1170475748705; Fri, 02 Feb 2007 20:09:08 -0800 (PST) Received: by 10.78.105.8 with HTTP; Fri, 2 Feb 2007 20:09:08 -0800 (PST) Message-ID: <302670f20702022009x417a210fm5e0fa36d860a225@mail.gmail.com> Date: Fri, 2 Feb 2007 23:09:08 -0500 From: "Gary Chambers" To: ljb Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux Cc: pgsql-php@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/3 X-Sequence-Number: 3686 Thanks for the reply! > pg_query_params() should have been made binary-safe, but it isn't. It only > accepts and passes 'text' mode arguments to PostgreSQL. So you cannot put > raw bytea data into a query parameter. Hmmm... Disappointing. Will pg_query_params ever become binary safe? I'm evaluating Postgres as an alternative to Oracle, so that's where the majority of my experience lies. > you need for a non-parameterized query, like "INSERT INTO mytable (bd) > VALUES ('$data')" where bd is a bytea column, and $data went through > pg_escape_bytea(). Understood. I do not like for several reasons that method of inserting data. It exposes me to SQL injection attacks, it's very inefficient (in Oracle, anyway -- perhaps you can correct me where Postgres is concerned), it seems uncharacteristic of a database with the qualities of Postgres, I can't have all my queries in a single source file, and I can't take advantage of the ease with which I can handle binary data with a bytea field. > To me, this means that you should probably do non-parameterized queries > instead, with pg_query() and pg_escape_bytea(), with your bytea data. Would there be any advantage to simply using a text field and base64 encoding and decoding the binary data? I really don't want to use non-parameterized queries. -- Gary Chambers // Nothing fancy and nothing Microsoft!