]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 281360: Checksetup should use the new DB-compatibility layer to create $dbh
authormkanat%kerio.com <>
Sat, 19 Feb 2005 02:53:17 +0000 (02:53 +0000)
committermkanat%kerio.com <>
Sat, 19 Feb 2005 02:53:17 +0000 (02:53 +0000)
Patch By Max Kanat-Alexander <mkanat@kerio.com> r=joel, r=glob, a=justdave

Bugzilla/DB.pm
checksetup.pl

index d1ecfcb2eb82ab501df8715d5fb296248b32d5d2..8ef05e12ee5550a66a9030d8f96bb5cf827662d8 100644 (file)
@@ -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>
index 350c71243ea409ceb85336c51a248d147ada9995..287b0baa6186ad95a3e1b83160e4b3b615490d7b 100755 (executable)
@@ -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 }