sub connect {
my ($self, @args) = @_;
+ my $initial_sql = $self->get_initial_sql;
- if (my $cached_dbh = SL::DBConnect::Cache->get(@args)) {
+ if (my $cached_dbh = SL::DBConnect::Cache->get(@args, $initial_sql)) {
return $cached_dbh;
}
my $dbh = $self->_connect(@args);
return undef if !$dbh;
- my $initial_sql = $self->get_initial_sql;
- $dbh->do($initial_sql) if $initial_sql;
-
- SL::DBConnect::Cache->store($dbh, @args);
+ if ($initial_sql) {
+ $dbh->do($initial_sql);
+ $dbh->commit if !$dbh->{AutoCommit};
+ }
+ SL::DBConnect::Cache->store($dbh, @args, $initial_sql);
return $dbh;
}
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;