Обсуждение: plperl: Documentation on BYTEA decoding is wrong
This doesn't work because '\' is turned into '\\' by PostgreSQL, and not '\134': my $arg = shift; $arg =~ s!\\(\d{3})!chr(oct($1))!ge; Something like this might be better: my $arg = shift; $arg =~ s!\\(?:\\|(\d{3}))!$1 ? chr(oct($1)) : "\\"!ge; You need to do this in one go because pre-escaped backslashes like like '\\101' cause problems otherwise. (All ''-delimited strings in this posting use strict SQL syntax, i.e. no escaped backslashes.) -- Florian Weimer <fweimer@bfk.de> BFK edv-consulting GmbH http://www.bfk.de/ Kriegsstraße 100 tel: +49-721-96201-1 D-76133 Karlsruhe fax: +49-721-96201-99
Florian Weimer wrote: > This doesn't work because '\' is turned into '\\' by PostgreSQL, and > not '\134': > > my $arg = shift; > $arg =~ s!\\(\d{3})!chr(oct($1))!ge; > > Something like this might be better: > > my $arg = shift; > $arg =~ s!\\(?:\\|(\d{3}))!$1 ? chr(oct($1)) : "\\"!ge; > > You need to do this in one go because pre-escaped backslashes like > like '\\101' cause problems otherwise. > > (All ''-delimited strings in this posting use strict SQL syntax, > i.e. no escaped backslashes.) > > I think you're right, although that's rather ugly ;-) I'll commit this change for now, but if anyone comes up with a simpler recipe I'll be happy. Also, it looks to me like I missed escaping \ on the way back, which I will fix. cheers andrew
On Friday 25 January 2008 10:11, Andrew Dunstan wrote: > Florian Weimer wrote: > > This doesn't work because '\' is turned into '\\' by PostgreSQL, and > > not '\134': > > > > my $arg = shift; > > $arg =~ s!\\(\d{3})!chr(oct($1))!ge; > > > > Something like this might be better: > > > > my $arg = shift; > > $arg =~ s!\\(?:\\|(\d{3}))!$1 ? chr(oct($1)) : "\\"!ge; > > > > You need to do this in one go because pre-escaped backslashes like > > like '\\101' cause problems otherwise. > > > > (All ''-delimited strings in this posting use strict SQL syntax, > > i.e. no escaped backslashes.) > > I think you're right, although that's rather ugly ;-) I'll commit this > change for now, but if anyone comes up with a simpler recipe I'll be happy. > Note we've been using Theo's plperl bytea patch on one of our production servers for some time; if anyone wants access to that lmk. -- Robert Treat Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL
* Robert Treat: > Note we've been using Theo's plperl bytea patch on one of our > production servers for some time; if anyone wants access to that > lmk. I'm interested. Could you post a pointer to this code, please? -- Florian Weimer <fweimer@bfk.de> BFK edv-consulting GmbH http://www.bfk.de/ Kriegsstraße 100 tel: +49-721-96201-1 D-76133 Karlsruhe fax: +49-721-96201-99
On Monday 28 January 2008 05:37:03 Florian Weimer wrote: > * Robert Treat: > > Note we've been using Theo's plperl bytea patch on one of our > > production servers for some time; if anyone wants access to that > > lmk. > > I'm interested. Could you post a pointer to this code, please? I had to do some work on this machine last week, and while digging into it, I ran across this email which appears to have fallen through the cracks. Not sure that anyone is still interested (heck, i've forgotten what this thread was even about), but the following patch should apply cleanly to 8.2.11. Note that personally I think this is a bit of a hack; I'd rather see a solution in the upstream code, but aiui this approach is frowned upon. If I get time, I might redo this as a new pl language (plperlo or something) rather than maintaing the patch. In any case, if anyone is interested on hacking on this, please drop us a line. -- Robert Treat Conjecture: http://www.xzilla.net Consulting: http://www.omniti.com