]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DBConnect.pm
Dispatcher: Client DB Handles cachen.
[mfinanz.git] / SL / DBConnect.pm
index afdf2c9e1b0902cf460016b36f29d6d9d7d61065..369cfe15889c16a8dc5b2d7ef2f126bd84c8c565 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',
@@ -33,18 +34,24 @@ sub _connect {
 sub connect {
   my ($self, @args) = @_;
 
+  if (my $cached_dbh = SL::DBConnect::Cache->get(@args)) {
+    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);
+
   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 +79,7 @@ sub get_connect_args {
 sub get_options {
   my $self    = shift;
   my $options = {
-    pg_enable_utf8 => $::locale->is_utf8,
+    pg_enable_utf8 => 1,
     @_
   };