sub _connect {
my ($self, @args) = @_;
- @args = $self->get_connect_args if !@args;
return DBI->connect(@args) unless $::lx_office_conf{debug} && $::lx_office_conf{debug}->{dbix_log4perl};
sub connect {
my ($self, @args) = @_;
+ @args = $self->get_connect_args if !@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;
}
Connects to the database. If the configuration parameter
C<debug.dbix_log4perl> is set then the call is made through
-L<DBIx::Log4per/connect>. Otherwise L<DBI/connect> is called directly.
+L<DBIx::Log4perl/connect>. Otherwise L<DBI/connect> is called directly.
In each case C<@dbi_args> is passed through as-is.