diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index e47517a1ac3..0527555af4f 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -116,7 +116,11 @@ public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); - return $params['dbname']; + if (isset($params['dbname'])) { + return $params['dbname']; + } + + return $conn->query('SELECT DB_NAME()')->fetchColumn(); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 883e447c129..35991a8a47f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -12,7 +12,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase * * @var \Doctrine\DBAL\Driver */ - private $driver; + protected $driver; protected function setUp() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php new file mode 100644 index 00000000000..0a4b13a55e0 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -0,0 +1,48 @@ +markTestSkipped('sqlanywhere is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('sqlanywhere only test.'); + } + } + + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + { + $params = $this->_conn->getParams(); + unset($params['dbname']); + + $connection = new Connection( + $params, + $this->_conn->getDriver(), + $this->_conn->getConfiguration(), + $this->_conn->getEventManager() + ); + + // SQL Anywhere has no "default" database. The name of the default database + // is defined on server startup and therefore can be arbitrary. + $this->assertInternalType('string', $this->driver->getDatabase($connection)); + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +}