Commit dbee8cd7 authored by Steve Müller's avatar Steve Müller

Merge pull request #572 from deeky666/fix-postgresql-reverse-engineering-quoted-tables

Fix reverse engineering quoted table names on PostgreSQL
parents 8291e820 0f7df49e
...@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Platforms; ...@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
...@@ -301,6 +302,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -301,6 +302,9 @@ class PostgreSqlPlatform extends AbstractPlatform
*/ */
public function getListTableConstraintsSQL($table) public function getListTableConstraintsSQL($table)
{ {
$table = new Identifier($table);
$table = $table->getName();
return "SELECT return "SELECT
quote_ident(relname) as relname quote_ident(relname) as relname
FROM FROM
...@@ -348,7 +352,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -348,7 +352,9 @@ class PostgreSqlPlatform extends AbstractPlatform
} else { } else {
$schema = "ANY(string_to_array((select replace(replace(setting,'\"\$user\"',user),' ','') from pg_catalog.pg_settings where name = 'search_path'),','))"; $schema = "ANY(string_to_array((select replace(replace(setting,'\"\$user\"',user),' ','') from pg_catalog.pg_settings where name = 'search_path'),','))";
} }
$whereClause .= "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = $schema";
$table = new Identifier($table);
$whereClause .= "$classAlias.relname = '" . $table->getName() . "' AND $namespaceAlias.nspname = $schema";
return $whereClause; return $whereClause;
} }
......
...@@ -301,6 +301,24 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -301,6 +301,24 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_binary')->getType()); $this->assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_binary')->getType());
$this->assertFalse($table->getColumn('column_binary')->getFixed()); $this->assertFalse($table->getColumn('column_binary')->getFixed());
} }
public function testListQuotedTable()
{
$offlineTable = new Schema\Table('user');
$offlineTable->addColumn('id', 'integer');
$offlineTable->addColumn('username', 'string', array('unique' => true));
$offlineTable->addColumn('fk', 'integer');
$offlineTable->setPrimaryKey(array('id'));
$offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id'));
$this->_sm->dropAndCreateTable($offlineTable);
$onlineTable = $this->_sm->listTableDetails('"user"');
$comparator = new Schema\Comparator();
$this->assertFalse($comparator->diffTable($offlineTable, $onlineTable));
}
} }
class MoneyType extends Type class MoneyType extends Type
......
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