| 1 | package Helios::ObjectDriver::DBI; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use base qw(Data::ObjectDriver::Driver::DBI); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 1 | our $VERSION = '2.61'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | # [LH] 2012-07-11: Changed the DBI connection creation to use connect_cached() | ||||||||||||||
| 11 | # instead of connect() to implement connection caching. Also added | ||||||||||||||
| 12 | # 'private_heliconn_$pid' option to ensure connections opened by separate | ||||||||||||||
| 13 | # processes stay separated. | ||||||||||||||
| 14 | |||||||||||||||
| 15 | |||||||||||||||
| 16 | 1 | my %Handles; | |||||||||||||
| 17 | sub init_db { | ||||||||||||||
| 18 | 0 | ▶ | my $driver = shift; | ||||||||||||
|
Subroutine
init_db: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 19 | 0 | my $dbh; | |||||||||||||
| 20 | 0 | ▶ | if ($driver->reuse_dbh) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | 0 | $dbh = $Handles{$driver->dsn}; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | 0 | ▶ | unless ($dbh) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 0 | eval { | |||||||||||||
| 25 | # [LH] 2012-07-11: Changed the DBI connection creation to use | ||||||||||||||
| 26 | # connect_cached() instead of connect() to implement connection | ||||||||||||||
| 27 | # caching. Also added 'private_heliconn_$pid' option to ensure | ||||||||||||||
| 28 | # connections opened by separate processes stay separated. | ||||||||||||||
| 29 | $dbh = DBI->connect_cached($driver->dsn, $driver->username, $driver->password, | ||||||||||||||
| 30 | { RaiseError => 1, PrintError => 0, AutoCommit => 1, 'private_heliconn_'.$$ => $$, | ||||||||||||||
| 31 | 0 | ▶ | %{$driver->connect_options || {}} }) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 32 | or Carp::croak("Connection error: " . $DBI::errstr); | ||||||||||||||
| 33 | }; | ||||||||||||||
| 34 | 0 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 0 | Carp::croak($@); | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | 0 | ▶ | if ($driver->reuse_dbh) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 0 | $Handles{$driver->dsn} = $dbh; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | 0 | $driver->dbd->init_dbh($dbh); | |||||||||||||
| 42 | 0 | $driver->{__dbh_init_by_driver} = 1; | |||||||||||||
| 43 | 0 | return $dbh; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | |||||||||||||||
| 47 | ▶ | sub DESTROY { | |||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||
| 48 | # [LH] 2012-07-11: Removed DBI->disconnect() call. | ||||||||||||||
| 49 | # Unlike in the base Data::ObjectDriver::Driver::DBI | ||||||||||||||
| 50 | # we don't want to disconnect the database connection | ||||||||||||||
| 51 | # EVEN IF we created it. | ||||||||||||||
| 52 | # We'll let DBI handle disconnection exclusively | ||||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | 1; | |||||||||||||
| 56 | __END__ | ||||||||||||||