On Tue, Nov 26, 2002 at 10:11:22AM -0800, David Wheeler wrote:
> On Monday, November 25, 2002, at 03:57 PM, David Wheeler wrote:
>
> >>If it doesn't work then yes (if $h->{Warn} is set, see Driver.xst for
> >>examples).
> >
> >Okay, I'll try to work up that patch tonight.
>
> Here's the patch. I would appreciate any feedback. I had to alter
> quote() quite a bit again, as it seems that DBD::Pg's quote() method is
> never invoked by
>
> $dbh->quote($val, DBI_SQL_BINARY);
(Which is correct per the spec.)
> But only by
>
> $dbh->quote($val, { TYPE => DBI_SQL_BINARY });
(Which is wrong.)
Check again. It makes no sense that they would invoke different methods.
Use trace.
> Tim, I had been under the impression that if a driver overrides quote()
> that it will always be called.
Yes.
> # Set up lookup for SQL types we don't want to escape.
> - my @no_escape = map { $_ => 1 }
> + my %no_escape = map { $_ => 1 }
> DBI::SQL_INTEGER, DBI::SQL_SMALLINT, DBI::SQL_DECIMAL,
> DBI::SQL_FLOAT, DBI::SQL_REAL, DBI::SQL_DOUBLE, DBI::SQL_NUMERIC;
>
> sub quote {
> my ($dbh, $str, $data_type) = @_;
> return "NULL" unless defined $str;
> - return $str if $data_type && $no_escape[$data_type];
> + $data_type = $data_type->{TYPE} if defined $data_type && ref $data_type;
> + return $str if $data_type && $no_escape{$data_type};
> +
> + if ($data_type && $data_type == DBI::SQL_BINARY) {
> + # We don't support SQL_BINARY.
> + my $msg = "Use of SQL_BINARY invalid in quote()";
> + unless ($dbh->FETCH('HandleError') &&
> + !$dbh->FETCH('HandleError')->($msg, $dbh)) {
> + Carp::croak($msg) if $dbh->FETCH('RaiseError');
> + Carp::carp ($msg) if $dbh->FETCH('PrintError');
> + }
> + }
The error handling is wrong. Replace the whole unless(){} with just
$h->DBI::set_err(1, "Use of SQL_BINARY invalid in quote()");
As per "Error handling" section of DBI::DBD docs.
(Generaly if you write a chunk of code and think "this ought to be
easier" it generally is. Or if it isn't then I'll make it so :-)
Tim.