#37100 [Opn->Asn]: data is returned truncated with BINARY CURSOR
| From: | tony2001@php.net | Date: | Sun, 16 Apr 2006 22:17:19 +0000 |
| Subject: | #37100 [Opn->Asn]: data is returned truncated with BINARY CURSOR | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-95871@lists.php.net to get a copy of this message | ||
ID: 37100
Updated by: tony2001@php.net
Reported By: e dot mauviere at geoclip dot fr
-Status: Open
+Status: Assigned
Bug Type: PostgreSQL related
Operating System: WIN XP PRO
PHP Version: 5.1.2
-Assigned To:
+Assigned To: helly
New Comment:
Marcus, please test the patch:
http://tony2001.phpclub.net/dev/tmp/bug37100.diff
I don't have/use PG, so unfortunately I can't do it myself.
Previous Comments:
------------------------------------------------------------------------
[2006-04-16 20:32:21] e dot mauviere at geoclip dot fr
Description:
------------
Impossible to retrieve properly binary data from a binary field in
Postgresql.
It should work with the SQL BINARY CURSOR OPTION in Postgres, but data
returned is truncated.
Reproduce code:
---------------
CREATE TABLE test(binfield byteA) ;
INSERT INTO test VALUES (decode('0103AA000812','hex'));
//First try
$data =pg_query("SELECT binfield FROM test");
$res=pg_fetch_result($data,0);
echo $res; // =>"\001\003\252\000\010\022"
echo bin2hex(pg_unescape_bytea($res)); //=> "0103aa000812"
//By default, Potsgresql returns binary field values as strings, so we
need to unescape them to restore original binary data. Tedious.
Performance issue here.
//second try
$sql="BEGIN;DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM
test;fetch all in mycursor;";
//the BINARY CURSOR option forces PostgreSQ to return binary data
$data =pg_query($sql);
$res=pg_fetch_result($data,0);
echo strlen($res); //=> 3
echo bin2hex($res); //=> 0103aa
//BUG : data returned is truncated, as soon as a "00" byte is
encountered,
Expected result:
----------------
i am expecting to retrieve full binary content
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37100&edit=1