Commit 4c691fde authored by Steve Müller's avatar Steve Müller Committed by Marco Pivetta

fix database and namespace introspection for SQL Server

parent d77aa767
...@@ -1028,7 +1028,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -1028,7 +1028,7 @@ class SQLServerPlatform extends AbstractPlatform
*/ */
public function getListDatabasesSQL() public function getListDatabasesSQL()
{ {
return 'SELECT * FROM SYS.DATABASES'; return 'SELECT * FROM sys.databases';
} }
/** /**
...@@ -1036,7 +1036,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -1036,7 +1036,7 @@ class SQLServerPlatform extends AbstractPlatform
*/ */
public function getListNamespacesSQL() 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')";
} }
/** /**
......
...@@ -95,6 +95,29 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -95,6 +95,29 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertContains('test_create_database', $databases); $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() public function testListTables()
{ {
$this->createTestTable('list_tables_test'); $this->createTestTable('list_tables_test');
......
...@@ -81,7 +81,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -81,7 +81,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
{ {
$dropDatabaseExpectation = 'DROP DATABASE foobar'; $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('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar')); $this->assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar')); $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
......
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