Revision c51601f0
Von Sven Schöling vor mehr als 9 Jahren hinzugefügt
SL/DBConnect.pm | ||
---|---|---|
33 | 33 |
|
34 | 34 |
sub connect { |
35 | 35 |
my ($self, @args) = @_; |
36 |
my $initial_sql = $self->get_initial_sql; |
|
36 | 37 |
|
37 |
if (my $cached_dbh = SL::DBConnect::Cache->get(@args)) { |
|
38 |
if (my $cached_dbh = SL::DBConnect::Cache->get(@args, $initial_sql)) {
|
|
38 | 39 |
return $cached_dbh; |
39 | 40 |
} |
40 | 41 |
|
41 | 42 |
my $dbh = $self->_connect(@args); |
42 | 43 |
return undef if !$dbh; |
43 | 44 |
|
44 |
my $initial_sql = $self->get_initial_sql; |
|
45 |
$dbh->do($initial_sql) if $initial_sql; |
|
46 |
|
|
47 |
SL::DBConnect::Cache->store($dbh, @args); |
|
45 |
if ($initial_sql) { |
|
46 |
$dbh->do($initial_sql); |
|
47 |
$dbh->commit if !$dbh->{AutoCommit}; |
|
48 |
} |
|
49 |
SL::DBConnect::Cache->store($dbh, @args, $initial_sql); |
|
48 | 50 |
|
49 | 51 |
return $dbh; |
50 | 52 |
} |
SL/DBConnect/Cache.pm | ||
---|---|---|
42 | 42 |
sub _args2str { |
43 | 43 |
my (@args) = @_; |
44 | 44 |
|
45 |
my ($dbconnect, $dbuser, $dbpasswd, $options) = @_; |
|
45 |
my ($dbconnect, $dbuser, $dbpasswd, $options, $initial_sql) = @_;
|
|
46 | 46 |
$dbconnect //= ''; |
47 | 47 |
$dbuser //= ''; |
48 | 48 |
$dbpasswd //= ''; |
... | ... | |
52 | 52 |
map { $_ => $options->{$_} } |
53 | 53 |
sort keys %$options; # deterministic order |
54 | 54 |
|
55 |
join ';', apply { s/([;\\])/\\$1/g } $dbconnect, $dbuser, $dbpasswd, $options_str; |
|
55 |
join ';', apply { s/([;\\])/\\$1/g } $dbconnect, $dbuser, $dbpasswd, $options_str, $initial_sql;
|
|
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
1; |
Auch abrufbar als: Unified diff
DB-Handle Caches: DATESTYLE korrekt setzen