Apache::DBI overrides disconnect() to be a no-op, and
connect_cached()
doesn't. (But Apache::DBI doesn't do this during startup.)
It would be reasonable for Apache::DBI to provide a way for
applications
to call disconnect() and have it actually disconnect.
If you want another hack :-), check out the source of DBIx::HA. I had
to go through a number of hoops to get around the Apache::DBI obsession
about holding on to the cached handle.
First you need to create a reverse lookup table:
---
if ($Apache::DBI::VERSION < 0.89) {
die "$prefix Requirement unmet. Apache::DBI must be at version 0.89 or
above";
}
# create a cached lookup table for finding the Apache::DBI cache key
index from the dsn
$DBIx::HA::ApacheDBIidx{$_->[0]} = _getApacheDBIidx(@$_);
Apache::DBI->setPingTimeOut($_->[0],
$DATABASE::conf{$dbname}->{'pingtimeout'} || -1);
}
sub _getApacheDBIidx {
# generates the ApacheDBI cache idx key from the passed dsn info
# first generate the same $idx key entry as ApacheDBI does
my @args = map { defined $_ ? $_ : "" } @_;
if ($args[0] =~ /^dbi:/i) { $args[0] =~ s/^dbi:[^:]+://io; }; # remove
the dbi:driver: piece
my $idx = join $;, $args[0], $args[1], $args[2];
if (3 == $#args and ref $args[3] eq "HASH") {
map { $idx .= "$;$_=$args[3]->{$_}" } sort keys %{$args[3]};
}
return $idx;
}
---
Then when you want to wipe the cached handle from Apache::DBI:
---
my $ApacheDBIConnections = Apache::DBI::all_handlers();
delete $$ApacheDBIConnections{$DBIx::HA::ApacheDBIidx{$olddsn}} if
($DBIx::HA::ApacheDBIidx{$olddsn});
---