binary cursor returning truncated data

This is a multi-part message in MIME format.

------=_NextPart_000_0201_01C65E4D.33A9DA20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

i am trying to retrieve binary content of a bytea field (or postgis =
geometry field) with a binary cursor with PHP :

$sql=3D"BEGIN;DECLARE mycursor BINARY CURSOR FOR SELECT shape FROM =
$layerName; fetch all in mycursor;"
.....pg_query...

But my shape field shows only two bytes of data.

Does someone know if it is a current PHP restriction ?

Thanks by advance,

Eric
------=_NextPart_000_0201_01C65E4D.33A9DA20
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2838" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>i am trying to retrieve binary content =
of a bytea
field (or postgis geometry field) with a binary cursor with PHP =
:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>$sql=3D"BEGIN;DECLARE mycursor BINARY =
CURSOR FOR
SELECT shape FROM $layerName; fetch all in mycursor;"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>....pg_query... </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>But my shape field shows only two =
bytes of
data.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Does someone know if it is a current =
PHP
restriction ?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks by advance,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Eric =
</FONT></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_0201_01C65E4D.33A9DA20--
e.mauviere [ Mi, 12 April 2006 16:21 ] [ ID #1271130 ]

Re: binary cursor returning truncated data

On Wed, Apr 12, 2006 at 04:21:49PM +0200, Eric Mauvire wrote:
> i am trying to retrieve binary content of a bytea field (or postgis
> geometry field) with a binary cursor with PHP :
>
> $sql="BEGIN;DECLARE mycursor BINARY CURSOR FOR SELECT shape FROM $layerName; fetch all in mycursor;"
> ....pg_query...
>
> But my shape field shows only two bytes of data.

The PHP source code (ext/pgsql/pgsql.c) doesn't have any calls to
PQfformat or PQbinaryTuples so PHP appears to expect text data.
Looks like you'll have to fetch data in text format and use
pg_unescape_bytea.

Maybe the PHP developers would consider adding support for binary
data (or maybe they already have and rejected the idea; I don't
know). Try asking on a PHP mailing list.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo [at] postgresql.org so that your
message can get through to the mailing list cleanly
Michael Fuhr [ So, 16 April 2006 18:39 ] [ ID #1275849 ]

Re: binary cursor returning truncated data

Thank you Michael,
for that confirmation

I reported the bug to the PHP team, and they issued a patch.

I would also suggest to postgres developpers to simplify their code and g=
o
back to SQL standards :)
That BINARY CURSOR thing should be avoided. With MySQL for instance, a
cursor will read the same way any type of data, binary or text.

Best regards,

Eric Mauvi=E8re

----- Original Message -----
From: "Michael Fuhr" <mike [at] fuhr.org>
To: "Eric Mauvi=E8re" <e.mauviere [at] geoclip.fr>
Cc: <pgsql-php [at] postgresql.org>
Sent: Sunday, April 16, 2006 6:39 PM
Subject: Re: [PHP] binary cursor returning truncated data


> On Wed, Apr 12, 2006 at 04:21:49PM +0200, Eric Mauvire wrote:
>> i am trying to retrieve binary content of a bytea field (or postgis
>> geometry field) with a binary cursor with PHP :
>>
>> $sql=3D"BEGIN;DECLARE mycursor BINARY CURSOR FOR SELECT shape FROM
>> $layerName; fetch all in mycursor;"
>> ....pg_query...
>>
>> But my shape field shows only two bytes of data.
>
> The PHP source code (ext/pgsql/pgsql.c) doesn't have any calls to
> PQfformat or PQbinaryTuples so PHP appears to expect text data.
> Looks like you'll have to fetch data in text format and use
> pg_unescape_bytea.
>
> Maybe the PHP developers would consider adding support for binary
> data (or maybe they already have and rejected the idea; I don't
> know). Try asking on a PHP mailing list.
>
> --
> Michael Fuhr
>
> ---------------------------(end of broadcast)--------------------------=
-
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo [at] postgresql.org so that your
> message can get through to the mailing list cleanly
>
>




---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
e.mauviere [ Di, 18 April 2006 10:01 ] [ ID #1278455 ]

Re: binary cursor returning truncated data

> for that confirmation
>
> I reported the bug to the PHP team, and they issued a patch.
>
> I would also suggest to postgres developpers to simplify their code and
> go back to SQL standards :)
> That BINARY CURSOR thing should be avoided. With MySQL for instance, a
> cursor will read the same way any type of data, binary or text.

I think you're rather confused. The BINARY CURSOR is for emitted binary
data, not reading it. If you declare a normal cursor over a binary
(bytea) field, you will get its text representation quite happily.

Chris



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Christopher Kings-Lyn[1] [ Di, 18 April 2006 10:28 ] [ ID #1278456 ]

Re: binary cursor returning truncated data

Hello Christopher,

i simply want to retrieve the content of a binary field in a Postgresql
table, and use that information in a PHP script.
That binary field contains binary information that must be read with PHP
binary functions (unpack).

The current way : POSTGRES cursor -> text version of the binary field in
PHP -> conversion back to a binary string with pg_unescape_bytea
is tedious and brings performance issues.

best regards,

Eric Mauvi=E8re

----- Original Message -----
From: "Christopher Kings-Lynne" <chris.kings-lynne [at] calorieking.com>
To: "Eric Mauvi=E8re" <e.mauviere [at] geoclip.fr>
Cc: <pgsql-php [at] postgresql.org>
Sent: Tuesday, April 18, 2006 10:28 AM
Subject: Re: [PHP] binary cursor returning truncated data


>> for that confirmation
>>
>> I reported the bug to the PHP team, and they issued a patch.
>>
>> I would also suggest to postgres developpers to simplify their code an=
d
>> go back to SQL standards :)
>> That BINARY CURSOR thing should be avoided. With MySQL for instance, a=

>> cursor will read the same way any type of data, binary or text.
>
> I think you're rather confused. The BINARY CURSOR is for emitted binar=
y
> data, not reading it. If you declare a normal cursor over a binary
> (bytea) field, you will get its text representation quite happily.
>
> Chris
>
>
>
> ---------------------------(end of broadcast)--------------------------=
-
> TIP 5: don't forget to increase your free space map settings
>
>




---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
e.mauviere [ Di, 18 April 2006 10:44 ] [ ID #1278457 ]

Re: binary cursor returning truncated data

Is this issue still open?

Some guys say me that they experience similar troubles and this may
prevent them from migrating from OneBigWellKnownDBMS to Postgres.

On 4/18/06, Eric Mauvi=E8re <e.mauviere [at] geoclip.fr> wrote:
> Hello Christopher,
>
> i simply want to retrieve the content of a binary field in a Postgresql
> table, and use that information in a PHP script.
> That binary field contains binary information that must be read with PHP
> binary functions (unpack).
>
> The current way : POSTGRES cursor -> text version of the binary field in
> PHP -> conversion back to a binary string with pg_unescape_bytea
> is tedious and brings performance issues.
>
> best regards,
>
> Eric Mauvi=E8re
>
> ----- Original Message -----
> From: "Christopher Kings-Lynne" <chris.kings-lynne [at] calorieking.com>
> To: "Eric Mauvi=E8re" <e.mauviere [at] geoclip.fr>
> Cc: <pgsql-php [at] postgresql.org>
> Sent: Tuesday, April 18, 2006 10:28 AM
> Subject: Re: [PHP] binary cursor returning truncated data
>
>
> >> for that confirmation
> >>
> >> I reported the bug to the PHP team, and they issued a patch.
> >>
> >> I would also suggest to postgres developpers to simplify their code and
> >> go back to SQL standards :)
> >> That BINARY CURSOR thing should be avoided. With MySQL for instance, a
> >> cursor will read the same way any type of data, binary or text.
> >
> > I think you're rather confused. The BINARY CURSOR is for emitted binary
> > data, not reading it. If you declare a normal cursor over a binary
> > (bytea) field, you will get its text representation quite happily.
> >
> > Chris
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: don't forget to increase your free space map settings
> >
> >
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>


--
Best regards,
Nikolay

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Nikolay Samokhvalov [ Do, 07 September 2006 11:13 ] [ ID #1458247 ]
Datenbanken » gmane.comp.db.postgresql.php » binary cursor returning truncated data

Vorheriges Thema: Having problems with user defined sessions using postgresql as mysession manager
Nächstes Thema: Postgres 8.1.4 + PHP, hangs when querying more than 16 records!