diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 48b86a4ab..dd7f0bd0e 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -211,6 +211,46 @@ class Connection { return $this->_driver->getDatabase($this); } + + /** + * Gets the hostname of the currently connected database. + * + * @return string + */ + public function getHost() + { + return $this->_params['host']; + } + + /** + * Gets the port of the currently connected database. + * + * @return mixed + */ + public function getPort() + { + return $this->_params['port']; + } + + /** + * Gets the username used by this connection. + * + * @return string + */ + public function getUsername() + { + return $this->_params['user']; + } + + /** + * Gets the password used by this connection. + * + * @return string + */ + public function getPassword() + { + return $this->_params['password']; + } /** * Gets the DBAL driver instance. @@ -349,8 +389,8 @@ class Connection } $query = 'DELETE FROM ' - . $this->quoteIdentifier($tableName) - . ' WHERE ' . implode(' AND ', $criteria); + . $this->quoteIdentifier($tableName) + . ' WHERE ' . implode(' AND ', $criteria); return $this->exec($query, array_values($identifier)); } @@ -578,8 +618,7 @@ class Connection * * @param string $query sql query * @param array $params query parameters - * - * @return PDOStatement + * @return integer * @todo Rename to executeUpdate(). */ public function exec($query, array $params = array()) diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 2742c8bf0..cc9087ad8 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -227,19 +227,15 @@ abstract class AbstractSchemaManager } /** - * Drop the database for this connection + * Drops a database. + * + * NOTE: You can not drop the database this SchemaManager is currently connected to. * * @param string $database The name of the database to drop - * @return boolean $result */ - public function dropDatabase($database = null) + public function dropDatabase($database) { - if (is_null($database)) { - $database = $this->_conn->getDatabase(); - } - $sql = $this->_platform->getDropDatabaseSql($database); - - return $this->_executeSql($sql, 'execute'); + $this->_conn->exec($this->_platform->getDropDatabaseSql($database)); } /** diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index cec9c6e6c..d19400add 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -264,26 +264,4 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager return array_merge($decl, $description); } - - /** - * Drops a database. - * If no database name is given, then the database this SchemaManager is - * currently connected to is dropped. In order to do this, the connection is - * closed and reopened on the "template1" database. - * - * @param string $database The name of the database to drop. - * @return boolean $result - * @override - */ - public function dropDatabase($database = null) - { - if (is_null($database)) { - //TODO: How to deal with this? We need to connect to another database - // in order to drop this one! - $database = $this->_conn->getDatabase(); - } - $sql = $this->_platform->getDropDatabaseSql($database); - - return $this->_executeSql($sql, 'execute'); - } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/DbalFunctionalTestSuite.php b/tests/Doctrine/Tests/DbalFunctionalTestSuite.php index 0237a91c4..e6c78cbd8 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestSuite.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestSuite.php @@ -13,6 +13,7 @@ class DbalFunctionalTestSuite extends DbalTestSuite protected function tearDown() { + $this->sharedFixture['conn']->close(); $this->sharedFixture = null; } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 3603f8782..4771f4766 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -33,8 +33,10 @@ class TestUtil public static function getConnection() { if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'], - $GLOBALS['db_host'], $GLOBALS['db_name'], $GLOBALS['db_port'])) { - $params = array( + $GLOBALS['db_host'], $GLOBALS['db_name'], $GLOBALS['db_port']) && + isset($GLOBALS['tmpdb_type'], $GLOBALS['tmpdb_username'], $GLOBALS['tmpdb_password'], + $GLOBALS['tmpdb_host'], $GLOBALS['tmpdb_name'], $GLOBALS['tmpdb_port'])) { + $realDbParams = array( 'driver' => $GLOBALS['db_type'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], @@ -42,10 +44,29 @@ class TestUtil 'dbname' => $GLOBALS['db_name'], 'port' => $GLOBALS['db_port'] ); - $conn = \Doctrine\DBAL\DriverManager::getConnection($params); - $conn->getSchemaManager()->dropAndCreateDatabase(); - $conn->close(); - $conn->connect(); + $tmpDbParams = array( + 'driver' => $GLOBALS['tmpdb_type'], + 'user' => $GLOBALS['tmpdb_username'], + 'password' => $GLOBALS['tmpdb_password'], + 'host' => $GLOBALS['tmpdb_host'], + 'dbname' => $GLOBALS['tmpdb_name'], + 'port' => $GLOBALS['tmpdb_port'] + ); + + // Connect to tmpdb in order to drop and create the real test db. + $tmpConn = \Doctrine\DBAL\DriverManager::getConnection($tmpDbParams); + $realConn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams); + + $dbname = $realConn->getDatabase(); + $realConn->close(); + + $tmpConn->getSchemaManager()->dropDatabase($dbname); + $tmpConn->getSchemaManager()->createDatabase($dbname); + + $tmpConn->close(); + + $conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams); + } else { $params = array( 'driver' => 'pdo_sqlite', diff --git a/tests/dbproperties.xml.dev b/tests/dbproperties.xml.dev index 592bf0a98..d1a6cc979 100644 --- a/tests/dbproperties.xml.dev +++ b/tests/dbproperties.xml.dev @@ -13,11 +13,20 @@ --> + + + + + + + + + \ No newline at end of file