Re: DBD::Pg BYTEA Character Escaping

Bruce Momjian <pgman@candle.pha.pa.us>

From: Bruce Momjian <pgman@candle.pha.pa.us>
To: David Wheeler <david@wheeler.net>
Cc: pgsql-general@postgresql.org
Date: 2001-11-18T05:45:17Z
Lists: 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