Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBAL-1218] Fix retrieving the database name connected to for SQL Anywhere #847

Merged
merged 2 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}