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-1058] Fix database and namespace introspection for SQL Server #736

Merged
merged 1 commit into from
Jan 12, 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
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,15 @@ public function getConcatExpression()
*/
public function getListDatabasesSQL()
{
return 'SELECT * FROM SYS.DATABASES';
return 'SELECT * FROM sys.databases';
}

/**
* {@inheritDoc}
*/
public function getListNamespacesSQL()
{
return "SELECT name FROM SYS.SCHEMAS WHERE name NOT IN('guest', 'INFORMATION_SCHEMA', 'sys')";
return "SELECT name FROM sys.schemas WHERE name NOT IN('guest', 'INFORMATION_SCHEMA', 'sys')";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ public function testListDatabases()
$this->assertContains('test_create_database', $databases);
}

/**
* @group DBAL-1058
*/
public function testListNamespaceNames()
{
if (!$this->_sm->getDatabasePlatform()->supportsSchemas()) {
$this->markTestSkipped('Platform does not support schemas.');
}

// Currently dropping schemas is not supported, so we have to workaround here.
$namespaces = $this->_sm->listNamespaceNames();
$namespaces = array_map('strtolower', $namespaces);

if (!in_array('test_create_schema', $namespaces)) {
$this->_conn->executeUpdate($this->_sm->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema'));

$namespaces = $this->_sm->listNamespaceNames();
$namespaces = array_map('strtolower', $namespaces);
}

$this->assertContains('test_create_schema', $namespaces);
}

public function testListTables()
{
$this->createTestTable('list_tables_test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testGeneratesDDLSnippets()
{
$dropDatabaseExpectation = 'DROP DATABASE foobar';

$this->assertEquals('SELECT * FROM SYS.DATABASES', $this->_platform->getListDatabasesSQL());
$this->assertEquals('SELECT * FROM sys.databases', $this->_platform->getListDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
Expand Down