$dbh;
}
+sub reset_all {
+ $_->{AutoCommit} || $_->rollback for values %cache;
+}
+
sub clear {
%cache = ();
}
+sub disconnect_all_and_clear {
+ $_->disconnect for values %cache;
+ %cache = ();
+}
+
sub _args2str {
my (@args) = @_;
- my ($dbconnect, $dbuser, $dbpasswd, $options) = @_;
+ my ($dbconnect, $dbuser, $dbpasswd, $options, $initial_sql) = @_;
$dbconnect //= '';
$dbuser //= '';
$dbpasswd //= '';
map { $_ => $options->{$_} }
sort keys %$options; # deterministic order
- join ';', apply { s/([;\\])/\\$1/g } $dbconnect, $dbuser, $dbpasswd, $options_str;
+ join ';', apply { $_ //= ''; s/([;\\])/\\$1/g } $dbconnect, $dbuser, $dbpasswd, $options_str, $initial_sql;
}
1;
=head1 SYNOPSIS
- use SL::SBConnect::Cache;
+ use SL::DBConnect::Cache;
- my $dbh = SL::DBConnct::Cache->get(@args);
- SL::DBConnct::Cache->store($dbh, @args);
+ my $dbh = SL::DBConnect::Cache->get(@args);
+ SL::DBConnect::Cache->store($dbh, @args);
# reset a cached handle
- SL::DBConnct::Cache->reset($dbh);
+ SL::DBConnect::Cache->reset($dbh);
# close a cached handle and forget it
- SL::DBConnct::Cache->close($dbh);
+ SL::DBConnect::Cache->close($dbh);
- SL::DBConnct::Cache->clear($dbh);
+ SL::DBConnect::Cache->clear($dbh);
=head1 DESCRIPTION
-Implementes a managed cache for DB connection handles.
+Implements a managed cache for DB connection handles.
The same would be possible with C<< DBI->connect_cached >>, but in that case,
-we would have no control ver the cache.
+we would have no control over the cache.
=head1 METHODS
=item * C<clear>
-Emties the cache. If handles are not referenced otherwise, they will get
+Empties the cache. If handles are not referenced otherwise, they will get
dropped and closed.
=back