Re: DBD::Pg BYTEA Character Escaping - Mailing list pgsql-general

From Bruce Momjian
Subject Re: DBD::Pg BYTEA Character Escaping
Date
Msg-id 200111180545.fAI5jHx12256@candle.pha.pa.us
Whole thread Raw
In response to DBD::Pg BYTEA Character Escaping  (David Wheeler <david@wheeler.net>)
List pgsql-general
> 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;
>
> 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.
>
> Thanks!
>
> David
>
> PS: If discussion of this issue needs to be moved to the Hackers list,
> I'll be happy to do so. I just thought I'd try here, first.

Yes, you only need to escape NULL for bytea.  The above patch looks fine
to me.  We can add it to 7.3.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

pgsql-general by date:

Previous
From: David Wheeler
Date:
Subject: DBD::Pg BYTEA Character Escaping
Next
From: Tom Lane
Date:
Subject: Re: DBD::Pg BYTEA Character Escaping