projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
epic-s6g
[kivitendo-erp.git]
/
SL
/
DBConnect.pm
diff --git
a/SL/DBConnect.pm
b/SL/DBConnect.pm
index
afdf2c9
..
9fcf7f4
100644
(file)
--- a/
SL/DBConnect.pm
+++ b/
SL/DBConnect.pm
@@
-4,6
+4,7
@@
use strict;
use DBI;
use SL::DB;
use DBI;
use SL::DB;
+use SL::DBConnect::Cache;
my %dateformat_to_datestyle = (
'yy-mm-dd' => 'ISO',
my %dateformat_to_datestyle = (
'yy-mm-dd' => 'ISO',
@@
-15,7
+16,6
@@
my %dateformat_to_datestyle = (
sub _connect {
my ($self, @args) = @_;
sub _connect {
my ($self, @args) = @_;
- @args = $self->get_connect_args if !@args;
return DBI->connect(@args) unless $::lx_office_conf{debug} && $::lx_office_conf{debug}->{dbix_log4perl};
return DBI->connect(@args) unless $::lx_office_conf{debug} && $::lx_office_conf{debug}->{dbix_log4perl};
@@
-32,19
+32,28
@@
sub _connect {
sub connect {
my ($self, @args) = @_;
sub connect {
my ($self, @args) = @_;
+ @args = $self->get_connect_args if !@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 $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 $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 {
}
sub get_initial_sql {
@@
-72,7
+81,7
@@
sub get_connect_args {
sub get_options {
my $self = shift;
my $options = {
sub get_options {
my $self = shift;
my $options = {
- pg_enable_utf8 =>
$::locale->is_utf8
,
+ pg_enable_utf8 =>
1
,
@_
};
@_
};
@@
-110,7
+119,7
@@
optionally routing through DBIx::Log4perl
Connects to the database. If the configuration parameter
C<debug.dbix_log4perl> is set then the call is made through
Connects to the database. If the configuration parameter
C<debug.dbix_log4perl> is set then the call is made through
-L<DBIx::Log4per/connect>. Otherwise L<DBI/connect> is called directly.
+L<DBIx::Log4per
l
/connect>. Otherwise L<DBI/connect> is called directly.
In each case C<@dbi_args> is passed through as-is.
In each case C<@dbi_args> is passed through as-is.