Commit 583e141a authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-168 - Fix bug with PostgreSQL schema handling

parent 64329fcb
...@@ -210,8 +210,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -210,8 +210,7 @@ class PostgreSqlPlatform extends AbstractPlatform
( (
SELECT c.oid SELECT c.oid
FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n
WHERE " .$this->getTableWhereClause($table) ." WHERE " .$this->getTableWhereClause($table) ." AND n.oid = c.relnamespace
AND n.oid = c.relnamespace
) )
AND r.contype = 'f'"; AND r.contype = 'f'";
} }
...@@ -259,15 +258,22 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -259,15 +258,22 @@ class PostgreSqlPlatform extends AbstractPlatform
) AND pg_index.indexrelid = oid"; ) AND pg_index.indexrelid = oid";
} }
/**
* @param string $table
* @param string $classAlias
* @param string $namespaceAlias
* @return string
*/
private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n') private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n')
{ {
$whereClause = ""; $whereClause = $namespaceAlias.".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND ";
if (strpos($table, ".") !== false) { if (strpos($table, ".") !== false) {
list($schema, $table) = explode(".", $table); list($schema, $table) = explode(".", $table);
$whereClause = "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = '" . $schema . "'"; $whereClause .= "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = '" . $schema . "'";
} else { } else {
$whereClause = "$classAlias.relname = '" . $table . "'"; $whereClause .= "$classAlias.relname = '" . $table . "'";
} }
return $whereClause; return $whereClause;
} }
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Ticket;
/**
* @group DBAL-168
*/
class DBAL168Test extends \Doctrine\Tests\DbalFunctionalTestCase
{
public function testDomainsTable()
{
if ($this->_conn->getDatabasePlatform()->getName() != "postgresql") {
$this->markTestSkipped('PostgreSQL only test');
}
$table = new \Doctrine\DBAL\Schema\Table("domains");
$table->addColumn('id', 'integer');
$table->addColumn('parent_id', 'integer');
$table->setPrimaryKey(array('id'));
$table->addForeignKeyConstraint('domains', array('parent_id'), array('id'));
$this->_conn->getSchemaManager()->createTable($table);
$table = $this->_conn->getSchemaManager()->listTableDetails('domains');
$this->assertEquals('domains', $table->getName());
}
}
\ No newline at end of file
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