<!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>&nbsp;</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&nbsp;not possible with 
Postgresql.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</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>&nbsp;</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;&nbsp; // 
=&gt;"\001\003\252\000\010\022"<BR>echo bin2hex(pg_unescape_bytea($res)); 
//=&gt; "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>&nbsp;</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);&nbsp; 
//=&gt; 3<BR>echo bin2hex($res); //=&gt; 0103aa</FONT></DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>I also reported that issue and suggested&nbsp;on postgresql-php 
list&nbsp;that&nbsp;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,&nbsp;should be avoided. With MySQL for instance, a&nbsp;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>&nbsp;</DIV>
<DIV>Eric Mauvière</DIV>
<DIV>===========</DIV>
<DIV><A href="http://www.geoclip.net">www.geoclip.net</A><BR></DIV>
<DIV>&gt; From: Markus Schaber &lt;<A 
href="mailto:schabi@logix-tt.com">schabi@logix-tt.com</A>&gt;<BR>&gt; Subject: 
Re: [postgis-users] binary cursor returning truncated data<BR>&gt; To: PostGIS 
Users Discussion &lt;<A 
href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</A>&gt;<BR>&gt; 
Message-ID: &lt;<A 
href="mailto:4444D1D8.6070505@logix-tt.com">4444D1D8.6070505@logix-tt.com</A>&gt;<BR>&gt; 
Content-Type: text/plain; charset=ISO-8859-1<BR>&gt; <BR>&gt; Hi, Eric,<BR>&gt; 
<BR>&gt; Eric Mauvière wrote:<BR>&gt; <BR>&gt;&gt; i am trying to retrieve 
binary content of a bytea field (or postgis<BR>&gt;&gt; geometry field) with a 
binary cursor with PHP :<BR>&gt;&gt;&nbsp; <BR>&gt;&gt; $sql="BEGIN;DECLARE 
mycursor BINARY CURSOR FOR SELECT shape FROM<BR>&gt;&gt; $layerName; fetch all 
in mycursor;"<BR>&gt;&gt; ....pg_query...<BR>&gt;&gt;&nbsp; <BR>&gt;&gt; But my 
shape field shows only two bytes of data.<BR>&gt;&gt;&nbsp; <BR>&gt;&gt; Does 
someone know if it is a current PHP restriction ?<BR>&gt; <BR>&gt; For 
geometries, the third byte is likely to be a 0-byte. So I think that<BR>&gt; PHP 
cannot cope with binary contents.<BR>&gt; <BR>&gt; Can you try with a binary 
cursor and bytea type, and if it fails there,<BR>&gt; too, ask on a 
postgresql-php list as they may be more esperienced with this?<BR>&gt; <BR>&gt; 
HTH,<BR>&gt; Markus<BR></DIV></BODY></HTML>