projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Leeren String in undef für anständige DB-Abfrage umwandeln
[kivitendo-erp.git]
/
SL
/
DB.pm
diff --git
a/SL/DB.pm
b/SL/DB.pm
index
4a78738
..
491a033
100644
(file)
--- a/
SL/DB.pm
+++ b/
SL/DB.pm
@@
-13,22
+13,40
@@
__PACKAGE__->use_private_registry;
my (%_db_registered, %_initial_sql_executed);
my (%_db_registered, %_initial_sql_executed);
+sub dbi_connect {
+ shift;
+
+ return SL::DBConnect->connect(@_);
+}
+
sub create {
my $domain = shift || SL::DB->default_domain;
my $type = shift || SL::DB->default_type;
sub create {
my $domain = shift || SL::DB->default_domain;
my $type = shift || SL::DB->default_type;
-
my
($domain, $type) = _register_db($domain, $type);
+ ($domain, $type) = _register_db($domain, $type);
my $db = __PACKAGE__->new_or_cached(domain => $domain, type => $type);
my $db = __PACKAGE__->new_or_cached(domain => $domain, type => $type);
+ _execute_initial_sql($db);
+
return $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;
sub _register_db {
my $domain = shift;
my $type = shift;
my %connect_settings;
+ my $initial_sql;
if (!%::myconfig) {
$type = 'LXOFFICE_EMPTY';
if (!%::myconfig) {
$type = 'LXOFFICE_EMPTY';
@@
-37,27
+55,33
@@
sub _register_db {
} elsif ($type eq 'LXOFFICE_AUTH') {
%connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg',
database => $::auth->{DB_config}->{db},
} elsif ($type eq 'LXOFFICE_AUTH') {
%connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg',
database => $::auth->{DB_config}->{db},
- host => $::auth->{DB_config}->{host},
+ host => $::auth->{DB_config}->{host}
|| 'localhost'
,
port => $::auth->{DB_config}->{port} || 5432,
username => $::auth->{DB_config}->{user},
password => $::auth->{DB_config}->{password},
connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8,
});
} else {
port => $::auth->{DB_config}->{port} || 5432,
username => $::auth->{DB_config}->{user},
password => $::auth->{DB_config}->{password},
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},
%connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg',
database => $::myconfig{dbname},
- host => $::myconfig{dbhost},
+ host => $::myconfig{dbhost}
|| 'localhost'
,
port => $::myconfig{dbport} || 5432,
username => $::myconfig{dbuser},
password => $::myconfig{dbpasswd},
connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8,
port => $::myconfig{dbport} || 5432,
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);
$domain = 'LXOFFICE' if $type =~ m/^LXOFFICE/;
}
my %flattened_settings = _flatten_settings(%connect_settings);
$domain = 'LXOFFICE' if $type =~ m/^LXOFFICE/;
- $type .= join($SUBSCRIPT_SEPARATOR, map { ($_, $flattened_settings{$_}) } sort keys %flattened_settings);
+ $type .= join($SUBSCRIPT_SEPARATOR, map { ($_, $flattened_settings{$_}
|| ''
) } sort keys %flattened_settings);
my $idx = "${domain}::${type}";
if (!$_db_registered{$idx}) {
my $idx = "${domain}::${type}";
if (!$_db_registered{$idx}) {
@@
-72,6
+96,19
@@
sub _register_db {
return ($domain, $type);
}
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 = ();
sub _flatten_settings {
my %settings = @_;
my %flattened = ();