From eff166f5c743592f126587f8d93ed6ef15b67959 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 14 Jan 2020 22:07:10 +0300 Subject: [PATCH] [pg] fix getting table information if search_path contains escaped schema name (eg "812pp") also simplifies the code and now exactly matches postgresql search rules --- lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php | 2 +- .../Schema/PostgreSqlSchemaManagerTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index e570dc04ab0..dd90f2cb6b3 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -367,7 +367,7 @@ private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias [$schema, $table] = explode('.', $table); $schema = $this->quoteStringLiteral($schema); } else { - $schema = "ANY(string_to_array((select replace(replace(setting,'\"\$user\"',user),' ','') from pg_catalog.pg_settings where name = 'search_path'),','))"; + $schema = 'ANY(current_schemas(false))'; } $table = new Identifier($table); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 35326968798..b8a26af3c65 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -335,6 +335,18 @@ public function testListQuotedTable() : void self::assertFalse($comparator->diffTable($offlineTable, $onlineTable)); } + public function testListTableDetailsWhenCurrentSchemaNameQuoted() : void + { + $this->connection->exec('CREATE SCHEMA "001_test"'); + $this->connection->exec('SET search_path TO "001_test"'); + + try { + $this->testListQuotedTable(); + } finally { + $this->connection->close(); + } + } + public function testListTablesExcludesViews() : void { $this->createTestTable('list_tables_excludes_views');