Hi!
The following patch causes DBI::_::db::quote() to cache the prefixes and
suffixes from DBI::db::type_info(), saving repeated calls. This provides
a significant performance boost (perhaps 2x), if you also apply my previous
patch to DBI::_::db::type_info(), and a great boost (10x), if you don't.
(Once again, I cached the values in a new DB handle attribute, for better
or worse....) FYI. Thanks for listening. :-)
-Dean Kopesky / Bridge Information Systems / [EMAIL PROTECTED]
*** DBI.pm Mon Jun 4 14:01:39 2001
--- DBI.2.pm Mon Jul 2 16:58:53 2001
***************
*** 904,926 ****
sub quote {
my ($dbh, $str, $data_type) = @_;
return "NULL" unless defined $str;
unless ($data_type) {
$str =~ s/'/''/g; # ISO SQL2
return "'$str'";
}
! # Optimise for standard numerics which need no quotes
! return $str if $data_type == DBI::SQL_INTEGER
! || $data_type == DBI::SQL_SMALLINT
! || $data_type == DBI::SQL_DECIMAL
! || $data_type == DBI::SQL_FLOAT
! || $data_type == DBI::SQL_REAL
! || $data_type == DBI::SQL_DOUBLE
! || $data_type == DBI::SQL_NUMERIC;
! my $ti = $dbh->type_info($data_type);
! # XXX needs checking
! my $lp = $ti ? $ti->{LITERAL_PREFIX} || "" : "'";
! my $ls = $ti ? $ti->{LITERAL_SUFFIX} || "" : "'";
# XXX don't know what the standard says about escaping
# in the 'general case' (where $lp != "'").
# So we just do this and hope:
--- 904,932 ----
sub quote {
my ($dbh, $str, $data_type) = @_;
+
return "NULL" unless defined $str;
unless ($data_type) {
$str =~ s/'/''/g; # ISO SQL2
return "'$str'";
}
!
! $dbh->{'QuoteQuoteCache'} = [ {} , {} ] if ! $dbh->{'QuoteQuoteCache'};
! my ($prefixes, $suffixes) = @{$dbh->{'QuoteQuoteCache'}};
!
! my $lp = $prefixes->{$data_type};
! my $ls = $suffixes->{$data_type};
!
! if ( ! defined $lp || ! defined $ls )
! {
! my $ti = $dbh->type_info($data_type);
! # XXX needs checking
! $lp = $prefixes->{$data_type} =
! $ti ? $ti->{LITERAL_PREFIX} || "" : "'";
! $ls = $suffixes->{$data_type} =
! $ti ? $ti->{LITERAL_SUFFIX} || "" : "'";
! }
!
# XXX don't know what the standard says about escaping
# in the 'general case' (where $lp != "'").
# So we just do this and hope: