diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 505421e..4ec9f5b3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2427,9 +2427,17 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { // would leave Drupal in a nonfunctional state. static $container = NULL; if ($rebuild) { + // If there is an existing container, close open connnections. + if ($container) { + $container->get('database_manager')->closeConnection(); + } $container = NULL; } if (isset($new_container)) { + // If there is an existing container, close open connnections. + if ($container) { + $container->get('database_manager')->closeConnection(); + } $container = $new_container; } if (!isset($container)) { @@ -2451,11 +2459,11 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { ->setFactoryMethod('get') ->addArgument('config'); - // This will be overridden by settings.php in drupal_settings_initialize(). + // This will be overridden in drupal_settings_initialize(). $container->setParameter('database.info', array()); + $container->register('database_manager', 'Drupal\Core\Database\Database') ->addArgument('%database.info%'); - $container->register('database', 'Drupal\Core\Database\Connection') ->setFactoryService('database_manager') ->setFactoryMethod('getConnection') diff --git a/core/includes/database.inc b/core/includes/database.inc index aee3d7e..1c3c6d3 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -423,7 +423,7 @@ function db_escape_table($table) { * The escaped field name as a string. */ function db_escape_field($field) { - return drupal_container()->get('database_manager')->escapeField($field); + return drupal_container()->get('database')->escapeField($field); } /** diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index cd47c9b..e837965 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1076,6 +1076,10 @@ function install_database_errors($database, $settings_file) { ->setFactoryMethod('getConnection') ->addArgument('slave'); } + else { + // If there already is a service defined, close the connection first. + drupal_container()->get('database_manager')->closeConnection(); + } try { db_run_tasks($driver); diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index 09691f8..a9592e3 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -39,6 +39,8 @@ public function __construct($bin) { $bin = 'cache_' . $bin; } $this->bin = $bin; + // @todo: Replace this with a injected connection in + // http://drupal.org/node/1764474. $this->connection = drupal_container()->get('database'); } diff --git a/core/lib/Drupal/Core/Cache/InstallBackend.php b/core/lib/Drupal/Core/Cache/InstallBackend.php index 7e0dbef..f7ed4e7 100644 --- a/core/lib/Drupal/Core/Cache/InstallBackend.php +++ b/core/lib/Drupal/Core/Cache/InstallBackend.php @@ -43,6 +43,8 @@ public function __construct($bin) { $bin = 'cache_' . $bin; } $this->bin = $bin; + // @todo: Replace this with an injected connection in + // http://drupal.org/node/1764474. if (drupal_container()->has('database')) { $this->connection = drupal_container()->get('database'); } diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 1960874..66dd2f6 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -163,7 +163,7 @@ public function destroy() { // Destroy all references to this connection by setting them to NULL. // The Statement class attribute only accepts a new value that presents a // proper callable, so we reset it to PDOStatement. - $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array())); + $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array(NULL))); $this->schema = NULL; } diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index 78877ee..3b50f8b 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -97,7 +97,7 @@ public function __construct(array $database_info) { * * @see Drupal\Core\Database\Log */ - final public function startLog($logging_key, $key = 'default') { + public function startLog($logging_key, $key = 'default') { if (empty($this->logs[$key])) { $this->logs[$key] = new Log($key); @@ -132,7 +132,7 @@ public function __construct(array $database_info) { * * @see Drupal\Core\Database\Log */ - final public function getLog($logging_key, $key = 'default') { + public function getLog($logging_key, $key = 'default') { if (empty($this->logs[$key])) { return NULL; } @@ -152,7 +152,7 @@ public function __construct(array $database_info) { * @return Drupal\Core\Database\Connection * The corresponding connection object. */ - final public function getConnection($target = 'default', $key = NULL) { + public function getConnection($target = 'default', $key = NULL) { if (!isset($key)) { // By default, we want the active connection, set in setActiveConnection. @@ -184,7 +184,7 @@ public function __construct(array $database_info) { * TRUE if there is at least one database connection established, FALSE * otherwise. */ - final public function isActiveConnection() { + public function isActiveConnection() { return !empty($this->activeKey) && !empty($this->connections) && !empty($this->connections[$this->activeKey]); } @@ -194,7 +194,7 @@ public function __construct(array $database_info) { * @return * The previous database connection key. */ - final public function setActiveConnection($key = 'default') { + public function setActiveConnection($key = 'default') { if (!empty($this->databaseInfo[$key])) { $old_key = $this->activeKey; $this->activeKey = $key; @@ -205,7 +205,7 @@ public function __construct(array $database_info) { /** * Process the configuration file for database information. */ - final public function parseConnectionInfo($database_info) { + public function parseConnectionInfo($database_info) { foreach ($database_info as $index => $info) { foreach ($database_info[$index] as $target => $value) { // If there is no "driver" property, then we assume it's an array of @@ -279,7 +279,7 @@ public function addConnectionInfo($key, $target, $info) { * @param $connection * The connection key for which we want information. */ - final public function getConnectionInfo($key = 'default') { + public function getConnectionInfo($key = 'default') { if (!empty($this->databaseInfo[$key])) { return $this->databaseInfo[$key]; } @@ -295,7 +295,7 @@ public function addConnectionInfo($key, $target, $info) { * @return * TRUE in case of success, FALSE otherwise. */ - final public function renameConnection($old_key, $new_key) { + public function renameConnection($old_key, $new_key) { if (!empty($this->databaseInfo[$old_key]) && empty($this->databaseInfo[$new_key])) { // Migrate the database connection information. $this->databaseInfo[$new_key] = $this->databaseInfo[$old_key]; @@ -322,7 +322,7 @@ public function addConnectionInfo($key, $target, $info) { * @return * TRUE in case of success, FALSE otherwise. */ - final public function removeConnection($key) { + public function removeConnection($key) { if (isset($this->databaseInfo[$key])) { self::closeConnection(NULL, $key); unset($this->databaseInfo[$key]); @@ -345,11 +345,7 @@ public function addConnectionInfo($key, $target, $info) { * @throws Drupal\Core\Database\ConnectionNotDefinedException * @throws Drupal\Core\Database\DriverNotSpecifiedException */ - final protected function openConnection($key, $target, $database_info = array()) { - if (empty($this->databaseInfo)) { - self::parseConnectionInfo($database_info); - } - + protected function openConnection($key, $target) { // If the requested database does not exist then it is an unrecoverable // error. if (!isset($this->databaseInfo[$key])) { @@ -425,4 +421,13 @@ public function closeConnection($target = NULL, $key = NULL) { public function ignoreTarget($key, $target) { $this->ignoreTargets[$key][$target] = TRUE; } + + public function __destruct() { + if ($this->isActiveConnection()) { + // Register this as a shutdown function in __destruct() to make sure this + // happens after all other shotdown functions have been executed. + register_shutdown_function(array($this, 'closeConnection')); + $this->closeConnection(); + } + } } diff --git a/core/lib/Drupal/Core/Database/Statement.php b/core/lib/Drupal/Core/Database/Statement.php index c5b1735..dacf90c 100644 --- a/core/lib/Drupal/Core/Database/Statement.php +++ b/core/lib/Drupal/Core/Database/Statement.php @@ -50,9 +50,11 @@ public function execute($args = array(), $options = array()) { } } - $logger = $this->dbh->getLogger(); - if (!empty($logger)) { - $query_start = microtime(TRUE); + if ($this->dbh) { + $logger = $this->dbh->getLogger(); + if (!empty($logger)) { + $query_start = microtime(TRUE); + } } $return = parent::execute($args); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 64c0129..9ba31bb 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -905,13 +905,6 @@ protected function rebuildContainer() { // @see Drupal\Core\DrupalKernel::initializeContainer() $this->kernel = new DrupalKernel('testing', FALSE); - // Close any remaining connections in the previous container. - if (!empty($this->container)) { - // Close the connection. - $this->container->get('database_manager')->closeConnection(); - unset($this->container); - } - // The DrupalKernel does not update the container in drupal_container(), but // replaces it with a new object. We therefore need to replace the minimal // boostrap container that has been set up by TestBase::prepareEnvironment(). @@ -982,10 +975,6 @@ protected function tearDown() { // Restore the original container. drupal_container(self::$originalContainer); - // Close the connection. - $this->container->get('database_manager')->closeConnection(); - unset($this->container); - // Restore original globals. $GLOBALS['theme_key'] = $this->originalThemeKey; $GLOBALS['theme'] = $this->originalTheme; @@ -1007,7 +996,6 @@ protected function tearDown() { $conf = $this->originalConf; // Restore original statics and globals. - $language_interface = $this->originalLanguage; $GLOBALS['config_directories'] = $this->originalConfigDirectories; if (isset($this->originalPrefix)) { drupal_valid_test_ua($this->originalPrefix); diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php index 8bdc45e..5c8a337 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php @@ -29,30 +29,31 @@ function testConnectionRouting() { // Clone the master credentials to a slave connection. // Note this will result in two independent connection objects that happen // to point to the same place. - $connection_info = Database::getConnectionInfo('default'); - Database::addConnectionInfo('default', 'slave', $connection_info['default']); + $database = drupal_container()->get('database_manager'); + $connection_info = $database->getConnectionInfo('default'); + $database->addConnectionInfo('default', 'slave', $connection_info['default']); - $db1 = Database::getConnection('default', 'default'); - $db2 = Database::getConnection('slave', 'default'); + $db1 = $database->getConnection('default', 'default'); + $db2 = $database->getConnection('slave', 'default'); $this->assertNotNull($db1, 'default connection is a real connection object.'); $this->assertNotNull($db2, 'slave connection is a real connection object.'); $this->assertNotIdentical($db1, $db2, 'Each target refers to a different connection.'); // Try to open those targets another time, that should return the same objects. - $db1b = Database::getConnection('default', 'default'); - $db2b = Database::getConnection('slave', 'default'); + $db1b = $database->getConnection('default', 'default'); + $db2b = $database->getConnection('slave', 'default'); $this->assertIdentical($db1, $db1b, 'A second call to getConnection() returns the same object.'); $this->assertIdentical($db2, $db2b, 'A second call to getConnection() returns the same object.'); // Try to open an unknown target. $unknown_target = $this->randomName(); - $db3 = Database::getConnection($unknown_target, 'default'); + $db3 = $database->getConnection($unknown_target, 'default'); $this->assertNotNull($db3, 'Opening an unknown target returns a real connection object.'); $this->assertIdentical($db1, $db3, 'An unknown target opens the default connection.'); // Try to open that unknown target another time, that should return the same object. - $db3b = Database::getConnection($unknown_target, 'default'); + $db3b = $database->getConnection($unknown_target, 'default'); $this->assertIdentical($db3, $db3b, 'A second call to getConnection() returns the same object.'); } @@ -63,13 +64,14 @@ function testConnectionRoutingOverride() { // Clone the master credentials to a slave connection. // Note this will result in two independent connection objects that happen // to point to the same place. - $connection_info = Database::getConnectionInfo('default'); - Database::addConnectionInfo('default', 'slave', $connection_info['default']); + $database = drupal_container()->get('database_manager'); + $connection_info = $database->getConnectionInfo('default'); + $database->addConnectionInfo('default', 'slave', $connection_info['default']); - Database::ignoreTarget('default', 'slave'); + $database->ignoreTarget('default', 'slave'); - $db1 = Database::getConnection('default', 'default'); - $db2 = Database::getConnection('slave', 'default'); + $db1 = $database->getConnection('default', 'default'); + $db2 = $database->getConnection('slave', 'default'); $this->assertIdentical($db1, $db2, 'Both targets refer to the same connection.'); } @@ -78,12 +80,13 @@ function testConnectionRoutingOverride() { * Tests the closing of a database connection. */ function testConnectionClosing() { + $database = drupal_container()->get('database_manager'); // Open the default target so we have an object to compare. - $db1 = Database::getConnection('default', 'default'); + $db1 = $database->getConnection('default', 'default'); // Try to close the the default connection, then open a new one. - Database::closeConnection('default', 'default'); - $db2 = Database::getConnection('default', 'default'); + $database->closeConnection('default', 'default'); + $db2 = $database->getConnection('default', 'default'); // Opening a connection after closing it should yield an object different than the original. $this->assertNotIdentical($db1, $db2, 'Opening the default connection after it is closed returns a new object.'); @@ -93,10 +96,11 @@ function testConnectionClosing() { * Tests the connection options of the active database. */ function testConnectionOptions() { - $connection_info = Database::getConnectionInfo('default'); + $database = drupal_container()->get('database_manager'); + $connection_info = $database->getConnectionInfo('default'); // Be sure we're connected to the default database. - $db = Database::getConnection('default', 'default'); + $db = $database->getConnection('default', 'default'); $connectionOptions = $db->getConnectionOptions(); // In the MySQL driver, the port can be different, so check individual @@ -105,8 +109,8 @@ function testConnectionOptions() { $this->assertEqual($connection_info['default']['database'], $connectionOptions['database'], 'The default connection info database matches the current connection options database.'); // Set up identical slave and confirm connection options are identical. - Database::addConnectionInfo('default', 'slave', $connection_info['default']); - $db2 = Database::getConnection('slave', 'default'); + $database->addConnectionInfo('default', 'slave', $connection_info['default']); + $db2 = $database->getConnection('slave', 'default'); $connectionOptions2 = $db2->getConnectionOptions(); // Get a fresh copy of the default connection options. @@ -116,8 +120,8 @@ function testConnectionOptions() { // Set up a new connection with different connection info. $test = $connection_info['default']; $test['database'] .= 'test'; - Database::addConnectionInfo('test', 'default', $test); - $connection_info = Database::getConnectionInfo('test'); + $database->addConnectionInfo('test', 'default', $test); + $connection_info = $database->getConnectionInfo('test'); // Get a fresh copy of the default connection options. $connectionOptions = $db->getConnectionOptions(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php index 522a60f..cb82947 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php @@ -21,6 +21,8 @@ class ConnectionUnitTest extends UnitTestBase { protected $monitor; protected $originalCount; + protected $database; + public static function getInfo() { return array( 'name' => 'Connection unit tests', @@ -35,15 +37,14 @@ function setUp() { $this->key = 'default'; $this->originalTarget = 'default'; $this->target = 'DatabaseConnectionUnitTest'; + $this->database = drupal_container()->get('database_manager'); // Create an additional connection to monitor the connections being opened // and closed in this test. // @see TestBase::changeDatabasePrefix() - $connection_info = Database::getConnectionInfo('default'); - Database::addConnectionInfo('default', 'monitor', $connection_info['default']); - global $databases; - $databases['default']['monitor'] = $connection_info['default']; - $this->monitor = Database::getConnection('monitor'); + $connection_info = $this->database->getConnectionInfo('default'); + $this->database->addConnectionInfo('default', 'monitor', $connection_info['default']); + $this->monitor = $this->database->getConnection('monitor'); } /** @@ -51,11 +52,11 @@ function setUp() { */ protected function addConnection() { // Add a new target to the connection, by cloning the current connection. - $connection_info = Database::getConnectionInfo($this->key); - Database::addConnectionInfo($this->key, $this->target, $connection_info[$this->originalTarget]); + $connection_info = $this->database->getConnectionInfo($this->key); + $this->database->addConnectionInfo($this->key, $this->target, $connection_info[$this->originalTarget]); // Verify that the new target exists. - $info = Database::getConnectionInfo($this->key); + $info = $this->database->getConnectionInfo($this->key); // Note: Custom assertion message to not expose database credentials. $this->assertIdentical($info[$this->target], $connection_info[$this->key], 'New connection info found.'); } @@ -66,7 +67,7 @@ protected function addConnection() { * @return integer */ protected function getConnectionID() { - return (int) Database::getConnection($this->target, $this->key)->query('SELECT CONNECTION_ID()')->fetchField(); + return (int) $this->database->getConnection($this->target, $this->key)->query('SELECT CONNECTION_ID()')->fetchField(); } /** @@ -100,13 +101,13 @@ function testOpenClose() { // Add and open a new connection. $this->addConnection(); $id = $this->getConnectionID(); - Database::getConnection($this->target, $this->key); + $this->database->getConnection($this->target, $this->key); // Verify that there is a new connection. $this->assertConnection($id); // Close the connection. - Database::closeConnection($this->target, $this->key); + $this->database->closeConnection($this->target, $this->key); // Wait 20ms to give the database engine sufficient time to react. usleep(20000); @@ -121,16 +122,16 @@ function testOpenQueryClose() { // Add and open a new connection. $this->addConnection(); $id = $this->getConnectionID(); - Database::getConnection($this->target, $this->key); + $this->database->getConnection($this->target, $this->key); // Verify that there is a new connection. $this->assertConnection($id); // Execute a query. - Database::getConnection($this->target, $this->key)->query('SHOW TABLES'); + $this->database->getConnection($this->target, $this->key)->query('SHOW TABLES'); // Close the connection. - Database::closeConnection($this->target, $this->key); + $this->database->closeConnection($this->target, $this->key); // Wait 20ms to give the database engine sufficient time to react. usleep(20000); @@ -145,16 +146,16 @@ function testOpenQueryPrefetchClose() { // Add and open a new connection. $this->addConnection(); $id = $this->getConnectionID(); - Database::getConnection($this->target, $this->key); + $this->database->getConnection($this->target, $this->key); // Verify that there is a new connection. $this->assertConnection($id); // Execute a query. - Database::getConnection($this->target, $this->key)->query('SHOW TABLES')->fetchCol(); + $this->database->getConnection($this->target, $this->key)->query('SHOW TABLES')->fetchCol(); // Close the connection. - Database::closeConnection($this->target, $this->key); + $this->database->closeConnection($this->target, $this->key); // Wait 20ms to give the database engine sufficient time to react. usleep(20000); @@ -169,14 +170,14 @@ function testOpenSelectQueryClose() { // Add and open a new connection. $this->addConnection(); $id = $this->getConnectionID(); - Database::getConnection($this->target, $this->key); + $this->database->getConnection($this->target, $this->key); // Verify that there is a new connection. $this->assertConnection($id); // Create a table. $name = 'foo'; - Database::getConnection($this->target, $this->key)->schema()->createTable($name, array( + $this->database->getConnection($this->target, $this->key)->schema()->createTable($name, array( 'fields' => array( 'name' => array( 'type' => 'varchar', @@ -186,16 +187,16 @@ function testOpenSelectQueryClose() { )); // Execute a query. - Database::getConnection($this->target, $this->key)->select('foo', 'f') + $this->database->getConnection($this->target, $this->key)->select('foo', 'f') ->fields('f', array('name')) ->execute() ->fetchAll(); // Drop the table. - Database::getConnection($this->target, $this->key)->schema()->dropTable($name); + $this->database->getConnection($this->target, $this->key)->schema()->dropTable($name); // Close the connection. - Database::closeConnection($this->target, $this->key); + $this->database->closeConnection($this->target, $this->key); // Wait 20ms to give the database engine sufficient time to react. usleep(20000); diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/LoggingTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/LoggingTest.php index ad3c3c8..3d1c2d9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/LoggingTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/LoggingTest.php @@ -26,7 +26,8 @@ public static function getInfo() { * Tests that we can log the existence of a query. */ function testEnableLogging() { - $log = Database::startLog('testing'); + $database = drupal_container()->get('database_manager'); + $log = $database->startLog('testing'); db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol(); db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol(); @@ -34,7 +35,7 @@ function testEnableLogging() { // Trigger a call that does not have file in the backtrace. call_user_func_array('db_query', array('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo')))->fetchCol(); - $queries = Database::getLog('testing', 'default'); + $queries = $database->getLog('testing', 'default'); $this->assertEqual(count($queries), 3, 'Correct number of queries recorded.'); @@ -47,16 +48,17 @@ function testEnableLogging() { * Tests that we can run two logs in parallel. */ function testEnableMultiLogging() { - Database::startLog('testing1'); + $database = drupal_container()->get('database_manager'); + $database->startLog('testing1'); db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol(); - Database::startLog('testing2'); + $database->startLog('testing2'); db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol(); - $queries1 = Database::getLog('testing1'); - $queries2 = Database::getLog('testing2'); + $queries1 = $database->getLog('testing1'); + $queries2 = $database->getLog('testing2'); $this->assertEqual(count($queries1), 2, 'Correct number of queries recorded for log 1.'); $this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for log 2.'); @@ -68,16 +70,17 @@ function testEnableMultiLogging() { function testEnableTargetLogging() { // Clone the master credentials to a slave connection and to another fake // connection. - $connection_info = Database::getConnectionInfo('default'); - Database::addConnectionInfo('default', 'slave', $connection_info['default']); + $database = drupal_container()->get('database_manager'); + $connection_info = $database->getConnectionInfo('default'); + $database->addConnectionInfo('default', 'slave', $connection_info['default']); - Database::startLog('testing1'); + $database->startLog('testing1'); db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol(); db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'slave'));//->fetchCol(); - $queries1 = Database::getLog('testing1'); + $queries1 = $database->getLog('testing1'); $this->assertEqual(count($queries1), 2, 'Recorded queries from all targets.'); $this->assertEqual($queries1[0]['target'], 'default', 'First query used default target.'); @@ -92,7 +95,8 @@ function testEnableTargetLogging() { * target. */ function testEnableTargetLoggingNoTarget() { - Database::startLog('testing1'); + $database = drupal_container()->get('database_manager'); + $database->startLog('testing1'); db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol(); @@ -103,7 +107,7 @@ function testEnableTargetLoggingNoTarget() { // does not exist. db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'fake'))->fetchCol(); - $queries1 = Database::getLog('testing1'); + $queries1 = $database->getLog('testing1'); $this->assertEqual(count($queries1), 2, 'Recorded queries from all targets.'); $this->assertEqual($queries1[0]['target'], 'default', 'First query used default target.'); @@ -114,13 +118,14 @@ function testEnableTargetLoggingNoTarget() { * Tests that we can log queries separately on different connections. */ function testEnableMultiConnectionLogging() { + $database = drupal_container()->get('database_manager'); // Clone the master credentials to a fake connection. // That both connections point to the same physical database is irrelevant. - $connection_info = Database::getConnectionInfo('default'); - Database::addConnectionInfo('test2', 'default', $connection_info['default']); + $connection_info = $database->getConnectionInfo('default'); + $database->addConnectionInfo('test2', 'default', $connection_info['default']); - Database::startLog('testing1'); - Database::startLog('testing1', 'test2'); + $database->startLog('testing1'); + $database->startLog('testing1', 'test2'); db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol(); @@ -130,8 +135,8 @@ function testEnableMultiConnectionLogging() { db_set_active($old_key); - $queries1 = Database::getLog('testing1'); - $queries2 = Database::getLog('testing1', 'test2'); + $queries1 = $database->getLog('testing1'); + $queries2 = $database->getLog('testing1', 'test2'); $this->assertEqual(count($queries1), 1, 'Correct number of queries recorded for first connection.'); $this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for second connection.');