From ea502a0bc9fddc65bd56bd49255b28cf36050796 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 13 Jan 2011 10:28:49 +0100 Subject: [PATCH] =?utf8?q?Datumsformat=20f=C3=BCr=20RDBO=20auf=20dasselbe?= =?utf8?q?=20wie=20f=C3=BCr=20den=20Benutzer=20setzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/SL/DB.pm b/SL/DB.pm index 4a78738c2..b48a49e70 100644 --- a/SL/DB.pm +++ b/SL/DB.pm @@ -21,14 +21,26 @@ 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', + 'mm-dd-yy' => 'POSTGRES, US', + 'dd/mm/yy' => 'SQL, EUROPEAN', + 'dd-mm-yy' => 'POSTGRES, EUROPEAN', + 'dd.mm.yy' => 'GERMAN' + ); + sub _register_db { my $domain = shift; my $type = shift; my %connect_settings; + my $initial_sql; if (!%::myconfig) { $type = 'LXOFFICE_EMPTY'; @@ -44,6 +56,11 @@ sub _register_db { connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8, }); } else { + my $european_dates = 0; + if ($::myconfig{dateformat}) { + $european_dates = 1 if $_dateformats{ $::myconfig{dateformat} } =~ m/european/i; + } + %connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg', database => $::myconfig{dbname}, host => $::myconfig{dbhost}, @@ -51,7 +68,8 @@ sub _register_db { username => $::myconfig{dbuser}, password => $::myconfig{dbpasswd}, connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8, - }); + }, + european_dates => $european_dates); } my %flattened_settings = _flatten_settings(%connect_settings); @@ -72,6 +90,19 @@ 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 = (); -- 2.20.1