? .buildpath ? .project ? .settings ? database.inc-close-db-test.patch ? sites/default/files ? sites/default/settings.php Index: .htaccess =================================================================== RCS file: /cvs/drupal/drupal/.htaccess,v retrieving revision 1.103 diff -u -p -r1.103 .htaccess --- .htaccess 21 Jun 2009 10:48:06 -0000 1.103 +++ .htaccess 3 Aug 2009 23:45:26 -0000 @@ -19,7 +19,7 @@ ErrorDocument 404 /index.php # Force simple error message for requests for non-existent favicon.ico. # There is no end quote below, for compatibility with Apache 1.3. - ErrorDocument 404 "The requested file favicon.ico was not found. + ErrorDocument 404 "The requested file favicon.ico was not found." # Set the default handler. Index: includes/database/database.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/database.inc,v retrieving revision 1.69 diff -u -p -r1.69 database.inc --- includes/database/database.inc 30 Jul 2009 10:16:48 -0000 1.69 +++ includes/database/database.inc 3 Aug 2009 23:45:27 -0000 @@ -1364,6 +1364,29 @@ abstract class Database { } /** + * Closes a connection to the server specified by the given key and target. + * + * @param $target + * The database target name. Defaults to NULL meaning that all target + * connections will be closed. + * @param $key + * The database connection key. Defaults to NULL which means the active key. + */ + public static function closeConnection($target = NULL, $key = NULL) { + // Gets the active conection by default. + if (!isset($key)) { + $key = self::$activeKey; + } + // To close the connection, we need to unset the static variable. + if (isset($target)) { + unset(self::$connections[$key][$target]); + } + else { + unset(self::$connections[$key]); + } + } + + /** * Instruct the system to temporarily ignore a given key/target. * * At times we need to temporarily disable slave queries. To do so, @@ -2072,6 +2095,20 @@ function db_driver() { } /** + * Closes the active database connection. + * + * @param $options + * An array of options to control which connection is closed. Only the + * target key has any meaning in this case. + */ +function db_close(array $options = array()) { + if (!isset($options['options']) || empty($options['target'])) { + $options['target'] = NULL; + } + Database::closeConnection($options['target']); +} + +/** * @} End of "defgroup database". */ Index: modules/simpletest/tests/database_test.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/database_test.test,v retrieving revision 1.62 diff -u -p -r1.62 database_test.test --- modules/simpletest/tests/database_test.test 21 Jul 2009 01:56:36 -0000 1.62 +++ modules/simpletest/tests/database_test.test 3 Aug 2009 23:45:28 -0000 @@ -211,6 +211,13 @@ class DatabaseConnectionTestCase extends // Try to open that unknown target another time, that should return the same object. $db3b = Database::getConnection($unknown_target, 'default'); $this->assertIdentical($db3, $db3b, t('A second call to getConnection() returns the same object.')); + + // Try to close the the default connection and open a new one + Database::closeConnection('default', 'default'); + $db4 = Database::getConnection('default', 'default'); + + // This probably will not work + $this->assertNotIdentical($db1, $db4, t('Opening the default connection after it is closed returns a new object.')); } /**