On Wed, Feb 06, 2002 at 09:48:54AM +0100, Steffen Goeldner wrote:
> Tim Bunce wrote:
> >
> > On Tue, Feb 05, 2002 at 04:37:48PM +0100, Steffen Goeldner wrote:
> > > + sub sql_identifier_quote_char {
> > > + my $dbh = shift;
> > > + my $sth = $dbh->func('adSchemaDBInfoLiterals','OpenSchema');
> > > + while ( my $row = $sth->fetch ) {
> > > + return $row->[1] if $row->[0] eq 'QUOTE'; # XXX QUOTE_PREFIX,
>QUOTE_SUFFIX
> > > + }
> > > + return undef;
> > > + }
> >
> > Umm, expensive. Need a way to cache these...
>
> O.k., but see below ...
>
> > > + sub get_info {
> > > + my($dbh, $info_type) = @_;
> > > + require DBD::ADO::GetInfo;
> > > + if ( exists $DBD::ADO::GetInfo::odbc2ado{$info_type} ) {
> > > + return
>$dbh->{ado_conn}->Properties->{$DBD::ADO::GetInfo::odbc2ado{$info_type}}{Value};
> > > + }
> > > + my $v = $DBD::ADO::GetInfo::info{int($info_type)};
> > > + $v = $v->($dbh) if ref $v eq 'CODE';
> >
> > How about we change that last line to
> >
> > if (ref $v eq 'CODE') {
> > my $get_info_cache = $dbh->{dbd_get_info_cache} ||= {};
> > return $get_info_cache->{int($info_type)} if exists
>$get_info_cache->{int($info_type)};
> > $v = $get_info_cache->{int($info_type)} = $v->($dbh);
>
> I'm not sure if we can cache *every* value. Is it possible that a DBMS
> allows to change some properties at runtime (something like 'ALTER
> SESSION SET ...')?
Umm [grumble], you're right. How about this:
if (ref $v eq 'CODE') {
my $get_info_cache = $dbh->{dbd_get_info_cache} ||= {};
return $get_info_cache->{$info_type} if exists
$get_info_cache->{$info_type};
$v = $v->($dbh);
$get_info_cache->{$info_type} = ($v=$$v) if ref $v eq 'SCALAR';
}
So caching is the default and a CODE ref can indicate that it doesn't want the
value cached by returning a ref to the value.
Slightly odd but I think it's probably better than adding cache
logic to many individual subs.
Tim.