From: franco.ricci@phys.uniroma1.it
To: pgsql-bugs@postgresql.org
Subject: BUG #7586: PL/Perl problem
Date: Sat, 06 Oct 2012 14:14:47 +0000
Message-ID: <E1TKV9T-0007eI-6T@wrigleys.postgresql.org> (raw)
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 = shift;
my $llrp_bin = encode_message($llrp_xml);
my $tmp = "";
for(my $i = 0; $i < length($llrp_bin); $i = $i + 1)
{
my $val = substr($llrp_bin, $i, 1);
$tmp = $tmp . sprintf("\\%03o",ord($val));
}
$llrp_bin = $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('<llrp:SET_READER_CONFIG
xmlns:llrp="http://www.llrp.org/ltk/schema/core/encoding/xml/1.0";
Version="1" MessageID="2">
<llrp:ResetToFactoryDefault>0</llrp:ResetToFactoryDefault>
<llrp:KeepaliveSpec>
<llrp:KeepaliveTriggerType>Periodic</llrp:KeepaliveTriggerType>
<llrp:PeriodicTriggerValue>30000</llrp:PeriodicTriggerValue>
</llrp:KeepaliveSpec>
</llrp:SET_READER_CONFIG>');
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 = shift;
my $llrp_bin = encode_message($llrp_xml);
my $tmp = "";
for(my $i = 0; $i < length($llrp_bin); $i = $i + 1)
{
my $val = substr($llrp_bin, $i, 1);
$tmp = $tmp . sprintf("\\%03o",ord($val));
}
$llrp_bin = $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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: franco.ricci@phys.uniroma1.it
Subject: Re: BUG #7586: PL/Perl problem
In-Reply-To: <E1TKV9T-0007eI-6T@wrigleys.postgresql.org>
References: <E1TKV9T-0007eI-6T@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox