X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDBConnect.pm;h=9fcf7f412a7081475a3a37d6f8a1f1c30ba9c400;hb=65604fea85234a5ae3e787f7cafd81ece6b8621d;hp=7d3ea41088e086407c934f3ae03b1ba7ca210ef4;hpb=dbda14c263efd93aca3b7114015a47d86b8581e3;p=kivitendo-erp.git diff --git a/SL/DBConnect.pm b/SL/DBConnect.pm index 7d3ea4108..9fcf7f412 100644 --- a/SL/DBConnect.pm +++ b/SL/DBConnect.pm @@ -4,6 +4,7 @@ use strict; use DBI; use SL::DB; +use SL::DBConnect::Cache; my %dateformat_to_datestyle = ( 'yy-mm-dd' => 'ISO', @@ -15,7 +16,6 @@ my %dateformat_to_datestyle = ( 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}; @@ -32,19 +32,28 @@ sub _connect { 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, $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; + if ($initial_sql) { + $dbh->do($initial_sql); + $dbh->commit if !$dbh->{AutoCommit}; + } + SL::DBConnect::Cache->store($dbh, @args, $initial_sql); return $dbh; } sub get_datestyle { my ($self, $dateformat) = @_; - return $dateformat_to_datestyle{ $dateformat || $::myconfig{dateformat} }; + return $dateformat_to_datestyle{ $dateformat || $::myconfig{dateformat} // '' }; } sub get_initial_sql { @@ -110,7 +119,7 @@ optionally routing through DBIx::Log4perl Connects to the database. If the configuration parameter C is set then the call is made through -L. Otherwise L is called directly. +L. Otherwise L is called directly. In each case C<@dbi_args> is passed through as-is.