Re: DBD::Pg BYTEA Character Escaping

From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: David Wheeler <david(at)wheeler(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: DBD::Pg BYTEA Character Escaping
Date: 2001-11-18 16:40:57
Message-ID: Pine.BSO.4.10.10111181125440.23456-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 17 Nov 2001, David Wheeler wrote:

> The second issue, however, is that it doesn't appear to me that it's
> even necessary that non-printable characters be replaced. Although Alex
> Pilosov says that such an approach is needed:
>
> http://www.geocrawler.com/mail/msg.php3?msg_id=6509224&list=10
I didn't say it was needed :) I just had the easy way out and escaped
everything that might possibly need to be escaped.

> Joe Conway found that there were only three characters ('\', "'", and
> "\0") that needed to be escaped, and it was those three characters that
> Bruce Momjian documented for the forthcoming 7.2 release:
Right.

> http://www.geocrawler.com/mail/msg.php3?msg_id=6547225&list=10
>
> If that's true, then any solution escaping non-printable characters is
> overkill, and therefore only the three characters need to be escaped.
> And since it looks like two of them ('\' and "'") are already escaped
> before the non-printable characters are escaped in DBD::Pg, it then it
> seems that this code:
>
> if ($data_type == DBI::SQL_BINARY ||
> $data_type == DBI::SQL_VARBINARY ||
> $data_type == DBI::SQL_LONGVARBINARY) {
> $str=join("", map { isprint($_)?$_:'\\'.sprintf("%03o",ord($_)) }
> split //, $str);
> }
>
> Could be changed to:
>
> s/\0/\\000/g if $data_type == DBI::SQL_BINARY ||
> $data_type == DBI::SQL_VARBINARY ||
> $data_type == DBI::SQL_LONGVARBINARY;
Yep.

>
> So, the reason I'm posting this query is because I'd like to get
> confirmation, if possible, on this conclusion. Based on the feedback I
> receive, I will submit patches to the DBD::Pg maintainer.
Go right ahead.

-alex

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raoul Callaghan 2001-11-18 17:17:04 Postmaster on OSX 10.1.1 what's the deal?
Previous Message Tom Lane 2001-11-18 05:46:46 Re: DBD::Pg BYTEA Character Escaping