<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2838" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>Hi Markus,
</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>thank you for your answer, actually PHP can cope
with binary content, i am reading without any problem wkb content from MySql
binary fields,</FONT></DIV>
<DIV><FONT face=Arial size=2>but it is currently not possible with
Postgresql.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here is a simple test, with byteA type fields
rather than geometry type fields:</FONT></DIV>
<DIV><FONT face=Arial size=2><BR>CREATE TABLE test(binfield byteA) ;<BR>INSERT
INTO test VALUES (decode('0103AA000812','hex'));</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>//First try<BR>$data =pg_query("SELECT binfield
FROM test");<BR>$res=pg_fetch_result($data,0);<BR>echo $res; //
=>"\001\003\252\000\010\022"<BR>echo bin2hex(pg_unescape_bytea($res));
//=> "0103aa000812"<BR>//By default, Potsgresql returns binary field values
as strings, so we need to unescape them to restore original binary data.
Tedious.<BR>Performance issue here.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>//second try<BR>$sql="BEGIN;DECLARE mycursor BINARY
CURSOR FOR SELECT binfield FROM<BR>test;fetch all in mycursor;";<BR>//the BINARY
CURSOR option forces PostgreSQ to return binary data<BR>$data
=pg_query($sql);<BR>$res=pg_fetch_result($data,0); <BR>echo strlen($res);
//=> 3<BR>echo bin2hex($res); //=> 0103aa</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>//BUG : data returned is truncated, as soon as a
"00" byte is encountered, </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I submitted the bug to the </FONT><FONT face=Arial
size=2><FONT face="Times New Roman" size=3>PHP team, they very quickly wrote a
patch. I suppose it will be available on next PHP release.</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV>I also reported that issue and suggested on postgresql-php
list that Postgres developpers should simplify their code and go back
to SQL standards :)</DIV>
<DIV>They didn't seem to appreciate that kind of irony...</DIV>
<DIV>I consider that this weird BINARY CURSOR thing, specific to
Postgres, should be avoided. With MySQL for instance, a cursor will
read the same way any type of data, binary or text. <BR></DIV>
<DIV><FONT face=Arial size=2>Best regards,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV>Eric Mauvière</DIV>
<DIV>===========</DIV>
<DIV><A href="http://www.geoclip.net">www.geoclip.net</A><BR></DIV>
<DIV>> From: Markus Schaber <<A
href="mailto:schabi@logix-tt.com">schabi@logix-tt.com</A>><BR>> Subject:
Re: [postgis-users] binary cursor returning truncated data<BR>> To: PostGIS
Users Discussion <<A
href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</A>><BR>>
Message-ID: <<A
href="mailto:4444D1D8.6070505@logix-tt.com">4444D1D8.6070505@logix-tt.com</A>><BR>>
Content-Type: text/plain; charset=ISO-8859-1<BR>> <BR>> Hi, Eric,<BR>>
<BR>> Eric Mauvière wrote:<BR>> <BR>>> i am trying to retrieve
binary content of a bytea field (or postgis<BR>>> geometry field) with a
binary cursor with PHP :<BR>>> <BR>>> $sql="BEGIN;DECLARE
mycursor BINARY CURSOR FOR SELECT shape FROM<BR>>> $layerName; fetch all
in mycursor;"<BR>>> ....pg_query...<BR>>> <BR>>> But my
shape field shows only two bytes of data.<BR>>> <BR>>> Does
someone know if it is a current PHP restriction ?<BR>> <BR>> For
geometries, the third byte is likely to be a 0-byte. So I think that<BR>> PHP
cannot cope with binary contents.<BR>> <BR>> Can you try with a binary
cursor and bytea type, and if it fails there,<BR>> too, ask on a
postgresql-php list as they may be more esperienced with this?<BR>> <BR>>
HTH,<BR>> Markus<BR></DIV></BODY></HTML>