Handling vom initialen SQL (SET DateStyle ...) zentralisiert
[kivitendo-erp.git] / SL / DB.pm
index 2d394f6..54214c8 100644 (file)
--- a/SL/DB.pm
+++ b/SL/DB.pm
@@ -14,7 +14,7 @@ use base qw(Rose::DB);
 __PACKAGE__->db_cache_class('Rose::DBx::Cache::Anywhere');
 __PACKAGE__->use_private_registry;
 
-my (%_db_registered, %_initial_sql_executed);
+my (%_db_registered);
 
 sub dbi_connect {
   shift;
@@ -30,18 +30,9 @@ sub create {
 
   my $db = __PACKAGE__->new_or_cached(domain => $domain, type => $type);
 
-  _execute_initial_sql($db);
-
   return $db;
 }
 
-my %_dateformats = ( 'yy-mm-dd'   => 'ISO',
-                     'yyyy-mm-dd' => 'ISO',
-                     'mm/dd/yy'   => 'SQL, US',
-                     'dd/mm/yy'   => 'SQL, EUROPEAN',
-                     'dd.mm.yy'   => 'GERMAN'
-                   );
-
 sub _register_db {
   my $domain = shift;
   my $type   = shift;
@@ -49,15 +40,12 @@ sub _register_db {
   my %specific_connect_settings;
   my %common_connect_settings = (
     driver           => 'Pg',
+    european_dates   => ((SL::DBConnect->get_datestyle || '') =~ m/european/i) ? 1 : 0,
     connect_options  => {
       pg_enable_utf8 => $::locale && $::locale->is_utf8,
     },
   );
 
-  if ($::myconfig{dateformat}) {
-    $common_connect_settings{european_dates} = 1 if ($_dateformats{ $::myconfig{dateformat} } || '') =~ m/european/i;
-  }
-
   if (($type eq 'KIVITENDO_AUTH') && $::auth && $::auth->{DB_config} && $::auth->session_tables_present) {
     %specific_connect_settings = (
       database        => $::auth->{DB_config}->{db},
@@ -109,19 +97,6 @@ sub _register_db {
   return ($domain, $type);
 }
 
-sub _execute_initial_sql {
-  my ($db) = @_;
-
-  return if $_initial_sql_executed{$db} || !%::myconfig || !$::myconfig{dateformat};
-
-  $_initial_sql_executed{$db} = 1;
-
-  # Don't rely on dboptions being set properly. Chose them from
-  # dateformat instead.
-  my $pg_dateformat = $_dateformats{ $::myconfig{dateformat} };
-  $db->dbh->do("set DateStyle to '${pg_dateformat}'") if $pg_dateformat;
-}
-
 sub _flatten_settings {
   my %settings  = @_;
   my %flattened = ();