use Moo;
use DBI;
+use DBIx::Connector;
+our %Connector;
has 'dbh' => (
is => 'lazy',
my ($self, $db, $output) = @_;
my $sql_vers = $self->bz_server_version;
- $self->disconnect;
my $sql_want = $db->{db_version};
my $version_ok = vers_cmp($sql_vers, $sql_want) > -1 ? 1 : 0;
}
}
- $dbh->disconnect;
}
# A helper for bz_create_database and bz_check_requirements.
my $dbh;
my %connect_params = %{ Bugzilla->localconfig };
$connect_params{db_name} = '';
+ local %Connector = ();
my $conn_success = eval {
$dbh = _connect(\%connect_params);
};
# set up default attributes used to connect to the database
# (may be overridden by DB driver implementations)
- my $attributes = { RaiseError => 0,
+ my $attributes = { RaiseError => 1,
AutoCommit => 1,
PrintError => 0,
ShowErrorStatement => 1,
}
}
- # connect using our known info to the specified db
- my $dbh = DBI->connect($dsn, $user, $pass, $attributes)
- or die "\nCan't connect to the database.\nError: $DBI::errstr\n"
- . " Is your database installed and up and running?\n Do you have"
- . " the correct username and password selected in localconfig?\n\n";
+ my $connector = $Connector{"$user.$dsn"} //= DBIx::Connector->new($dsn, $user, $pass, $attributes);
- # RaiseError was only set to 0 so that we could catch the
- # above "die" condition.
- $dbh->{RaiseError} = 1;
-
- return $dbh;
+ return $connector->dbh;
}
#####################################################################
# every process, and Perl has another. (Various Perl modules still use
# the built-in rand(), even though we never use it in Bugzilla itself,
# so we need to srand() both of them.)
-PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); }"
+PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); eval { Bugzilla->dbh->ping } }"
PerlInitHandler Bugzilla::ModPerl::Hostage
PerlAccessHandler Bugzilla::ModPerl::BlockIP
'CPAN::Meta::Requirements' => '2.121',
'Class::XSAccessor' => '1.18',
'DBI' => '1.614',
+ 'DBIx::Connector' => 0,
'Data::Password::passwdqc' => '0.08',
'Date::Format' => '2.23',
'DateTime' => '0.75',
use Date::Parse;
use JSON qw( decode_json );
-my $dbh = Bugzilla->dbh;
+local our $dbh = Bugzilla->dbh;
local our $cgi = Bugzilla->cgi;
local our $template = Bugzilla->template;
local our $vars = {};