Commit 8de151d8 authored by romanb's avatar romanb

[2.0] Small cleanups

parent 2a9886af
...@@ -115,7 +115,7 @@ class Connection ...@@ -115,7 +115,7 @@ class Connection
* @var integer * @var integer
*/ */
protected $_transactionNestingLevel = 0; protected $_transactionNestingLevel = 0;
/** /**
* The currently active transaction isolation level. * The currently active transaction isolation level.
* *
...@@ -193,7 +193,7 @@ class Connection ...@@ -193,7 +193,7 @@ class Connection
} }
/** /**
* Get the array of parameters used to instantiated this connection instance * Gets the parameters used during instantiation.
* *
* @return array $params * @return array $params
*/ */
...@@ -203,7 +203,7 @@ class Connection ...@@ -203,7 +203,7 @@ class Connection
} }
/** /**
* Get the name of the database connected to for this Connection instance * Gets the name of the database this Connection is connected to.
* *
* @return string $database * @return string $database
*/ */
...@@ -262,18 +262,12 @@ class Connection ...@@ -262,18 +262,12 @@ class Connection
if ($this->_isConnected) return false; if ($this->_isConnected) return false;
$driverOptions = isset($this->_params['driverOptions']) ? $driverOptions = isset($this->_params['driverOptions']) ?
$this->_params['driverOptions'] : array(); $this->_params['driverOptions'] : array();
$user = isset($this->_params['user']) ? $user = isset($this->_params['user']) ? $this->_params['user'] : null;
$this->_params['user'] : null;
$password = isset($this->_params['password']) ? $password = isset($this->_params['password']) ?
$this->_params['password'] : null; $this->_params['password'] : null;
$this->_conn = $this->_driver->connect( $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
$this->_params,
$user,
$password,
$driverOptions
);
$this->_isConnected = true; $this->_isConnected = true;
......
...@@ -11,6 +11,11 @@ use Doctrine\DBAL\Platforms; ...@@ -11,6 +11,11 @@ use Doctrine\DBAL\Platforms;
*/ */
class Driver implements \Doctrine\DBAL\Driver class Driver implements \Doctrine\DBAL\Driver
{ {
/**
* Attempts to connect to the database and returns a driver connection on success.
*
* @return Doctrine\DBAL\Driver\Connection
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new \Doctrine\DBAL\Driver\PDOConnection( return new \Doctrine\DBAL\Driver\PDOConnection(
...@@ -24,7 +29,7 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -24,7 +29,7 @@ class Driver implements \Doctrine\DBAL\Driver
/** /**
* Constructs the Postgres PDO DSN. * Constructs the Postgres PDO DSN.
* *
* @return string The DSN. * @return string The DSN.
*/ */
private function _constructPdoDsn(array $params) private function _constructPdoDsn(array $params)
{ {
......
...@@ -879,6 +879,7 @@ abstract class AbstractSchemaManager ...@@ -879,6 +879,7 @@ abstract class AbstractSchemaManager
try { try {
return call_user_func_array(array($this, $method), $args); return call_user_func_array(array($this, $method), $args);
} catch (\Exception $e) { } catch (\Exception $e) {
//var_dump($e->getMessage());
return false; return false;
} }
} }
......
...@@ -189,12 +189,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -189,12 +189,8 @@ class OracleSchemaManager extends AbstractSchemaManager
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password; $query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password;
$result = $this->_conn->exec($query); $result = $this->_conn->exec($query);
try { $query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username;
$query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username; $result = $this->_conn->exec($query);
$result = $this->_conn->exec($query);
} catch (Exception $e) {
$this->dropDatabase($database);
}
return true; return true;
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.doctrine-project.org>.
*/ */
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
...@@ -264,4 +264,26 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -264,4 +264,26 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
return array_merge($decl, $description); 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
*/
public function dropDatabase($database = null)
{
if (is_null($database)) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getDropDatabaseSql($database);
//$this->_conn->close();
return $this->_executeSql($sql, 'execute');
}
} }
\ No newline at end of file
...@@ -107,11 +107,11 @@ class OrmFunctionalTestCase extends OrmTestCase ...@@ -107,11 +107,11 @@ class OrmFunctionalTestCase extends OrmTestCase
} }
} }
if ($classes) { if ($classes) {
try { //try {
$this->_schemaTool->createSchema($classes); $this->_schemaTool->createSchema($classes);
} catch (\Exception $e) { //} catch (\Exception $e) {
// Swallow all exceptions. We do not test the schema tool here. // Swallow all exceptions. We do not test the schema tool here.
} //}
} }
} }
......
...@@ -2,8 +2,34 @@ ...@@ -2,8 +2,34 @@
namespace Doctrine\Tests; namespace Doctrine\Tests;
/**
* TestUtil is a class with static utility methods used during tests.
*
* @author robo
*/
class TestUtil class TestUtil
{ {
/**
* Gets a <b>real</b> database connection using the following parameters
* of the $GLOBALS array:
*
* 'db_type' : The name of the Doctrine DBAL database driver to use.
* 'db_username' : The username to use for connecting.
* 'db_password' : The password to use for connecting.
* 'db_host' : The hostname of the database to connect to.
* 'db_name' : The name of the database to connect to.
* 'db_port' : The port of the database to connect to.
*
* Usually these variables of the $GLOBALS array are filled by PHPUnit based
* on an XML configuration file. If no such parameters exist, an SQLite
* in-memory database is used.
*
* IMPORTANT:
* 1) Each invocation of this method returns a NEW database connection.
* 2) The database is dropped and recreated to ensure it's clean.
*
* @return Doctrine\DBAL\Connection The database connection instance.
*/
public static function getConnection() public static function getConnection()
{ {
if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'], if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment