From 6e9fd1326e23f0e286c90229824df2e8e90c18af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Fri, 5 Dec 2014 18:25:20 +0100 Subject: [PATCH] fix database and namespace introspection for SQL Server --- .../DBAL/Platforms/PostgreSqlPlatform.php | 6 ++--- .../DBAL/Platforms/SQLServerPlatform.php | 4 ++-- .../SchemaManagerFunctionalTestCase.php | 23 +++++++++++++++++++ .../AbstractSQLServerPlatformTestCase.php | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 8d35ecc0235..e2b64cde406 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -236,9 +236,9 @@ public function getListDatabasesSQL() public function getListNamespacesSQL() { return "SELECT schema_name AS nspname - FROM information_schema.schemata - WHERE schema_name NOT LIKE 'pg_%' - AND schema_name != 'information_schema'"; + FROM information_schema.schemata + WHERE schema_name NOT LIKE 'pg_%' + AND schema_name != 'information_schema'"; } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index e41ceb27b40..4fc28b815f1 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1028,7 +1028,7 @@ public function getConcatExpression() */ public function getListDatabasesSQL() { - return 'SELECT * FROM SYS.DATABASES'; + return 'SELECT * FROM sys.databases'; } /** @@ -1036,7 +1036,7 @@ public function getListDatabasesSQL() */ 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')"; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 0f7e4028eb2..b9be4607b1a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -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'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 7714a6c438b..c99d0578d56 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -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'));