From 67a19cf48b775499364cf10f99319ef585039890 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Fri, 23 Apr 2010 05:21:19 +0000 Subject: #688294 by Berdir, andypost, Crell, catch: Fixed Switch from db_is_active() to proper exception catching. --- includes/database/database.inc | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'includes/database') diff --git a/includes/database/database.inc b/includes/database/database.inc index 91547a5b8..dda27d7ba 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -608,7 +608,7 @@ abstract class DatabaseConnection extends PDO { // Update the query with the new placeholders. // preg_replace is necessary to ensure the replacement does not affect // placeholders that start with the same exact text. For example, if the - // query contains the placeholders :foo and :foobar, and :foo has an + // query contains the placeholders :foo and :foobar, and :foo has an // array of values, using str_replace would affect both placeholders, // but using the following preg_replace would only affect :foo because // it is followed by a non-word character. @@ -1367,8 +1367,7 @@ abstract class Database { // If necessary, a new connection is opened. self::$connections[$key][$target] = self::openConnection($key, $target); } - - return isset(self::$connections[$key][$target]) ? self::$connections[$key][$target] : NULL; + return self::$connections[$key][$target]; } /** @@ -1501,11 +1500,11 @@ abstract class Database { // If the requested database does not exist then it is an unrecoverable // error. if (!isset(self::$databaseInfo[$key])) { - throw new Exception('DB does not exist'); + throw new DatabaseConnectionNotDefinedException('The specified database connection is not defined: ' . $key); } if (!$driver = self::$databaseInfo[$key][$target]['driver']) { - throw new Exception('Drupal is not set up'); + throw new DatabaseDriverNotSpecifiedException('Driver not specified for this database connection: ' . $key); } // We cannot rely on the registry yet, because the registry requires an @@ -1624,6 +1623,17 @@ class FieldsOverlapException extends Exception {} */ class NoFieldsException extends Exception {} +/** + * Exception thrown if an undefined database connection is requested. + */ +class DatabaseConnectionNotDefinedException extends Exception {} + +/** + * Exception thrown if no driver is specified for a database connection. + */ +class DatabaseDriverNotSpecifiedException extends Exception {} + + /** * A wrapper class for creating and managing database transactions. * @@ -2419,20 +2429,6 @@ function db_set_active($key = 'default') { return Database::setActiveConnection($key); } -/** - * Determines if there is an active connection. - * - * Note that this method will return FALSE if no connection has been established - * yet, even if one could be. - * - * @return - * TRUE if there is at least one database connection established, FALSE - * otherwise. - */ -function db_is_active() { - return Database::isActiveConnection(); -} - /** * Restricts a dynamic table, column, or constraint name to safe characters. * -- cgit v1.2.3