X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDBConnect.pm;h=4ee48733f612e68991c021b87334ed07c55a490c;hb=cb22586c142b9da5b5c08f4751367f2412a1cffb;hp=afdf2c9e1b0902cf460016b36f29d6d9d7d61065;hpb=841d44c00aae1166a0721e40dc2f9ffb7b9ac5b5;p=kivitendo-erp.git diff --git a/SL/DBConnect.pm b/SL/DBConnect.pm index afdf2c9e1..4ee48733f 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', @@ -32,19 +33,27 @@ sub _connect { sub connect { my ($self, @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 { @@ -72,7 +81,7 @@ sub get_connect_args { sub get_options { my $self = shift; my $options = { - pg_enable_utf8 => $::locale->is_utf8, + pg_enable_utf8 => 1, @_ };