Fix example of de-escaping bytea argument, per Florian Weimer. Also fix example
authorAndrew Dunstan <andrew@dunslane.net>
Fri, 25 Jan 2008 15:28:35 +0000 (15:28 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Fri, 25 Jan 2008 15:28:35 +0000 (15:28 +0000)
of escaping bytea return value. Both cases did not handle backslash values properly.

doc/src/sgml/plperl.sgml

index 826088c9c5f1afb52f22e81ac5d6e81c70c35798..11040c5700c8c714523b0bfa2a45eb3913b4e102 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.66 2007/05/04 14:55:32 adunstan Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.67 2008/01/25 15:28:35 adunstan Exp $ -->
 
  <chapter id="plperl">
   <title>PL/Perl - Perl Procedural Language</title>
@@ -150,7 +150,7 @@ $$ LANGUAGE plperl;
 
 <programlisting>
     my $arg = shift;
-    $arg =~ s!\\(\d{3})!chr(oct($1))!ge;
+    $arg =~ s!\\(?:\\|(\d{3}))!$1 ? chr(oct($1)) : "\\"!ge;
 </programlisting>
 
   </para>
@@ -161,7 +161,7 @@ $$ LANGUAGE plperl;
    is how to escape binary data for a return value of type <type>bytea</>:
 
 <programlisting>
-    $retval =~ s!([^ -~])!sprintf("\\%03o",ord($1))!ge;
+    $retval =~ s!(\\|[^ -~])!sprintf("\\%03o",ord($1))!ge;
     return $retval;
 </programlisting>