Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TKV9b-0002NU-RC for pgsql-bugs@postgresql.org; Sat, 06 Oct 2012 14:14:55 +0000 Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TKV9V-0004Vo-Tm for pgsql-bugs@postgresql.org; Sat, 06 Oct 2012 14:14:55 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TKV9U-0003qC-2t for pgsql-bugs@postgresql.org; Sat, 06 Oct 2012 14:14:48 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1TKV9T-0007eI-6T for pgsql-bugs@postgresql.org; Sat, 06 Oct 2012 14:14:47 +0000 Date: Sat, 06 Oct 2012 14:14:47 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7586: PL/Perl problem To: pgsql-bugs@postgresql.org From: franco.ricci@phys.uniroma1.it X-Pg-Spam-Score: -4.0 (----) X-Archive-Number: 201210/42 X-Sequence-Number: 34342 The following bug has been logged on the website: Bug reference: 7586 Logged by: Franco Ricci Email address: franco.ricci@phys.uniroma1.it PostgreSQL version: 9.0.10 Operating system: FreeBSD 9.0 Description: = I wrote the following function in Perl to make some operations with LLRP command in a RFID application: ---- CREATE OR REPLACE FUNCTION llrp_command.llrpenc_bytea(xml) RETURNS bytea AS $BODY$ use strict; use RFID::LLRP::Builder qw(encode_message); = my $llrp_xml =3D shift; my $llrp_bin =3D encode_message($llrp_xml); my $tmp =3D ""; for(my $i =3D 0; $i < length($llrp_bin); $i =3D $i + 1) { my $val =3D substr($llrp_bin, $i, 1); $tmp =3D $tmp . sprintf("\\%03o",ord($val)); } $llrp_bin =3D $tmp; return $llrp_bin; $BODY$ LANGUAGE plperlu IMMUTABLE STRICT COST 100; ALTER FUNCTION llrp_command.llrpenc_bytea(xml) OWNER TO "LLRP"; COMMENT ON FUNCTION llrp_command.llrpenc_bytea(xml) IS 'Encode a xml LLRP message in LLRP binary format and escape it into bytea'; ---- Until version 9.0.8 all works fine. Version 9.0.8, 9.0.9, 9.0.10 and 9.1.6 have some troubles. In particular when I call llrpenc_bytea function: SELECT llrp_command.llrpenc_bytea(' 0 Periodic 30000 '); it returns: ----- ERROR: Entity: line 1: parser error : Document is empty ^ Entity: line 1: parser error : Start tag expected, '<' not found ^ Compilation failed in require at line 3. BEGIN failed--compilation aborted at line 3. CONTEXT: compilation of PL/Perl function "llrpenc_bytea" ********** Error ********** ERROR: Entity: line 1: parser error : Document is empty ^ Entity: line 1: parser error : Start tag expected, '<' not found ^ Compilation failed in require at line 3. BEGIN failed--compilation aborted at line 3. SQL state: 42601 Context: compilation of PL/Perl function "llrpenc_bytea" -------- I tried to run the same script as a perl script and it runs fine so I think the problem is not Perl. Postgresql version 9.1.2 has no problem. I think the bug is about as postgresql passes xml argument to perl interpreter. The same function with a text argument works well: ---- REATE OR REPLACE FUNCTION llrp_command.llrpenc_bytea(text) RETURNS bytea AS $BODY$ use strict; use RFID::LLRP::Builder qw(encode_message); = my $llrp_xml =3D shift; my $llrp_bin =3D encode_message($llrp_xml); my $tmp =3D ""; for(my $i =3D 0; $i < length($llrp_bin); $i =3D $i + 1) { my $val =3D substr($llrp_bin, $i, 1); $tmp =3D $tmp . sprintf("\\%03o",ord($val)); } $llrp_bin =3D $tmp; return $llrp_bin; $BODY$ LANGUAGE plperlu IMMUTABLE STRICT COST 100; ALTER FUNCTION llrp_command.llrpenc_bytea(text) OWNER TO "LLRP"; COMMENT ON FUNCTION llrp_command.llrpenc_bytea(text) IS 'Encode a xml LLRP message in LLRP binary format and escape it into bytea'; ---- = Thanks a lot for your great work Regards Franco Ricci