Skip to content

Commit

Permalink
Merge pull request #847 from deeky666/DBAL-1218
Browse files Browse the repository at this point in the history
[DBAL-1218] Fix retrieving the database name connected to for SQL Anywhere
  • Loading branch information
Bill Schaller committed Sep 10, 2015
2 parents 9ea8b0a + 25a78e4 commit a7a5c4a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
*
* @var \Doctrine\DBAL\Driver
*/
private $driver;
protected $driver;

protected function setUp()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Doctrine\Tests\DBAL\Functional\Driver\SQLAnywhere;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\SQLAnywhere\Driver;
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;

class DriverTest extends AbstractDriverTest
{
protected function setUp()
{
if (! extension_loaded('sqlanywhere')) {
$this->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();
}
}

0 comments on commit a7a5c4a

Please sign in to comment.