Skip to content

Commit

Permalink
fix database and namespace introspection for SQL Server
Browse files Browse the repository at this point in the history
  • Loading branch information
deeky666 committed Dec 27, 2014
1 parent dde863a commit 6e9fd13
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'";
}

/**
Expand Down
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

0 comments on commit 6e9fd13

Please sign in to comment.