DeliveryOrder - Doku und Typos
[kivitendo-erp.git] / SL / DBConnect.pm
index 7d3ea41..4ee4873 100644 (file)
@@ -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 {