summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-02-19 03:53:17 +0100
committermkanat%kerio.com <>2005-02-19 03:53:17 +0100
commite9273ed3ae65db0e2c6f0b8889c852667a8f26b6 (patch)
tree018cb4026f03cb9d23f607887a78b7f5ce2b67db
parentf76ab38ea951522b2db8c356abb5aeb1414d3dcb (diff)
downloadbugzilla-e9273ed3ae65db0e2c6f0b8889c852667a8f26b6.tar.gz
bugzilla-e9273ed3ae65db0e2c6f0b8889c852667a8f26b6.tar.xz
Bug 281360: Checksetup should use the new DB-compatibility layer to create $dbh
Patch By Max Kanat-Alexander <mkanat@kerio.com> r=joel, r=glob, a=justdave
-rw-r--r--Bugzilla/DB.pm28
-rwxr-xr-xchecksetup.pl29
2 files changed, 25 insertions, 32 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index d1ecfcb2e..8ef05e12e 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -133,8 +133,11 @@ sub connect_shadow {
Param("shadowdbsock"), $db_user, $db_pass);
}
-sub connect_main {
- return _connect($db_driver, $db_host, $db_name, $db_port,
+sub connect_main (;$) {
+ my ($no_db_name) = @_;
+ my $connect_to_db = $db_name;
+ $connect_to_db = "" if $no_db_name;
+ return _connect($db_driver, $db_host, $connect_to_db, $db_port,
$db_sock, $db_user, $db_pass);
}
@@ -147,7 +150,9 @@ sub _connect {
my $pkg_module = "Bugzilla::DB::" . $db_module;
# do the actual import
- eval ("require $pkg_module") || die ($@);
+ eval ("require $pkg_module")
+ || die ("'$db_module' is not a valid choice for \$db_driver in "
+ . " localconfig: " . $@);
# instantiate the correct DB specific module
my $dbh = $pkg_module->new($user, $pass, $host, $dbname, $port, $sock);
@@ -279,7 +284,7 @@ sub db_new {
# set up default attributes used to connect to the database
# (if not defined by DB specific implementation)
- $attributes = { RaiseError => 1,
+ $attributes = { RaiseError => 0,
AutoCommit => 1,
PrintError => 0,
ShowErrorStatement => 1,
@@ -294,7 +299,14 @@ sub db_new {
# connect using our known info to the specified db
# Apache::DBI will cache this when using mod_perl
- my $self = DBI->connect($dsn, $user, $pass, $attributes);
+ my $self = 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";
+
+ # RaiseError was only set to 0 so that we could catch the
+ # above "die" condition.
+ $self->{RaiseError} = 1;
# class variables
$self->{private_bz_in_transaction} = 0;
@@ -362,7 +374,11 @@ should not be called from anywhere else.
Description: Function to connect to the main database, returning a new
database handle.
- Params: none
+ Params: $no_db_name (optional) - If true, Connect to the database
+ server, but don't connect to a specific database. This
+ is only used when creating a database. After you create
+ the database, you should re-create a new Bugzilla::DB object
+ without using this parameter.
Returns: new instance of the DB class
=item C<connect_shadow>
diff --git a/checksetup.pl b/checksetup.pl
index 350c71243..287b0baa6 100755
--- a/checksetup.pl
+++ b/checksetup.pl
@@ -803,12 +803,7 @@ if ($newstuff ne "") {
# care less whether they were defined ahead of time or not.
my $my_db_check = ${*{$main::{'db_check'}}{SCALAR}};
my $my_db_driver = ${*{$main::{'db_driver'}}{SCALAR}};
-my $my_db_host = ${*{$main::{'db_host'}}{SCALAR}};
-my $my_db_port = ${*{$main::{'db_port'}}{SCALAR}};
my $my_db_name = ${*{$main::{'db_name'}}{SCALAR}};
-my $my_db_user = ${*{$main::{'db_user'}}{SCALAR}};
-my $my_db_sock = ${*{$main::{'db_sock'}}{SCALAR}};
-my $my_db_pass = ${*{$main::{'db_pass'}}{SCALAR}};
my $my_index_html = ${*{$main::{'index_html'}}{SCALAR}};
my $my_create_htaccess = ${*{$main::{'create_htaccess'}}{SCALAR}};
my $my_webservergroup = ${*{$main::{'webservergroup'}}{SCALAR}};
@@ -1525,19 +1520,8 @@ if ($my_db_check) {
# Do we have the database itself?
my $sql_want = "3.23.41"; # minimum version of MySQL
-
-# original DSN line was:
-# my $dsn = "DBI:$my_db_driver:$my_db_name;$my_db_host;$my_db_port";
-# removed the $db_name because we don't know it exists yet, and this will fail
-# if we request it here and it doesn't. - justdave@syndicomm.com 2000/09/16
- my $dsn = "DBI:$my_db_driver:;$my_db_host;$my_db_port";
- if ($my_db_sock ne "") {
- $dsn .= ";mysql_socket=$my_db_sock";
- }
- my $dbh = DBI->connect($dsn, $my_db_user, $my_db_pass)
- or die "Can't connect to the $my_db_driver database. Is the database " .
- "installed and\nup and running? Do you have the correct username " .
- "and password selected in\nlocalconfig?\n\n";
+
+ my $dbh = Bugzilla::DB::connect_main("no database connection");
printf("Checking for %15s %-9s ", "MySQL Server", "(v$sql_want)") unless $silent;
my $qh = $dbh->prepare("SELECT VERSION()");
$qh->execute;
@@ -1586,14 +1570,7 @@ EOF
}
# now get a handle to the database:
-my $connectstring = "dbi:$my_db_driver:$my_db_name:host=$my_db_host:port=$my_db_port";
-if ($my_db_sock ne "") {
- $connectstring .= ";mysql_socket=$my_db_sock";
-}
-
-my $dbh = DBI->connect($connectstring, $my_db_user, $my_db_pass)
- or die "Can't connect to the table '$connectstring'.\n",
- "Have you read the Bugzilla Guide in the doc directory? Have you read the doc of '$my_db_driver'?\n";
+my $dbh = Bugzilla::DB::connect_main();
END { $dbh->disconnect if $dbh }