diff -u b/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php --- b/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -781,7 +781,6 @@ $this->expandArguments($query, $args); $stmt = $this->prepareStatement($query, $options); - try { $stmt->execute($args, $options); diff -u b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php --- b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -22,7 +22,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; -// cspell:ignore destid idmap sourceid +// cspell:ignore destid idmap sourceid psql /** * Defines the sql based ID map implementation. @@ -298,22 +298,7 @@ * The fully qualified map table name. */ public function getQualifiedMapTableName() { - $connection = $this->getDatabase(); - - switch ($connection->databaseType()) { - case 'psql': - // PostgreSQL doesn't support cross DB merges. So only use schema and - // prefixed table name. - $info => $connection->schema()->getPrefixInfo($this->mapTableName); - $qualifiedMapTableName = $info['schema'] . '.' . $info['table']; - break; - - default: - $qualifiedMapTableName = $connection->getFullQualifiedTableName($this->mapTableName); - break; - } - - return $qualifiedMapTableName; + return $this->getDatabase()->getFullQualifiedTableName($this->mapTableName); } /** diff -u b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php --- b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php @@ -73,8 +73,8 @@ * Constructs a connection object. */ public function __construct(\PDO $connection, array $connection_options) { - // We need to set the connectionOptions before the parent, - // because setPrefix needs this. + // We need to set the connectionOptions before the parent, because setPrefix + // needs this. $this->connectionOptions = $connection_options; parent::__construct($connection, $connection_options); @@ -314,11 +314,10 @@ */ public function getFullQualifiedTableName($table) { $options = $this->getConnectionOptions(); - $info = $this->schema()->getPrefixInfo($table); // The fully qualified table name in PostgreSQL is in the form of // ... - return $options['database'] . '.' . $info['schema'] . '.' . $info['table']; + return $options['database'] . '.' . $options['schema'] . '.' . $this->getPrefix() . $table; } /** diff -u b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php --- b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php @@ -58,14 +58,9 @@ $connectionInfo = $connection->getConnectionOptions(); - + // If the schema is not set in the connection options than schema defaults + // to public. $this->defaultSchema = $connectionInfo['schema'] ?? 'public'; - - // Set the default schema when it is not "public". - if (isset($connection_options['schema']) && ($connection_options['schema'] != 'public')) { - $this->connection->exec("SET SEARCH_PATH TO " . $connection_options['schema']); - } - } /** @@ -107,12 +102,12 @@ } if (strlen($identifierName) > $this->maxIdentifierLength) { - $saveIdentifier = 'drupal_' . $this->hashBase64($identifierName) . '_' . $tag; + $saveIdentifier = '"drupal_' . $this->hashBase64($identifierName) . '_' . $tag . '"'; } else { $saveIdentifier = $identifierName; } - return $this->connection->escapeTable($saveIdentifier); + return $saveIdentifier; } /** @@ -155,7 +150,5 @@ ]; $this->connection->addSavepoint(); - - try { // The bytea columns and sequences for a table can be found in diff -u b/core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php b/core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php --- b/core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php +++ b/core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php @@ -8,6 +8,8 @@ use Drupal\KernelTests\Core\Database\DatabaseTestSchemaInstallTrait; use Drupal\KernelTests\Core\Database\DriverSpecificKernelTestBase; +// cSpell:ignore nspname schemaname Upserting indexdef + /** * Tests schema API for the PostgreSQL driver. * @@ -39,7 +41,6 @@ $this->connection = Database::getConnection('testing_fake', 'default'); - $table_specification = [ 'description' => 'Schema table description may contain "quotes" and could be long—very long indeed.', 'fields' => [ @@ -79,8 +80,8 @@ $this->connection->insert('faking_table') ->fields( [ - 'id' => '1', - 'test_field' => '123', + 'id' => '1', + 'test_field' => '123', ] )->execute(); @@ -111,7 +112,7 @@ $this->assertTrue($this->connection->schema()->tableExists('faking_table')); // Hardcoded assertion that we created the table in the non-public schema. - $this->assertCount(1, $this->connection->query("SELECT * FROM pg_tables WHERE schemaname = 'testing_fake' AND tablename = :prefixedTable", [':prefixedTable' => $this->connection->getPrefix() . "faking_table"] )->fetchAll()); + $this->assertCount(1, $this->connection->query("SELECT * FROM pg_tables WHERE schemaname = 'testing_fake' AND tablename = :prefixedTable", [':prefixedTable' => $this->connection->getPrefix() . "faking_table"])->fetchAll()); } /** @@ -145,7 +146,6 @@ 'test_field' => '55', ])->execute(); - // Testing that the insert is correct. $results = $this->connection->select('faking_table')->fields('faking_table')->condition('id', '123')->execute()->fetchAll(); $this->assertIsArray($results); @@ -234,7 +234,6 @@ $this->assertSame('343', $merge_results[0]->test_field); } - /** * @covers \Drupal\Core\Database\Driver\pgsql\Connection::delete * @covers \Drupal\Core\Database\Driver\pgsql\Connection::truncate @@ -269,7 +268,7 @@ $this->assertTrue($this->connection->schema()->indexExists('faking_table', 'test_field')); - $results = $this->connection->query("SELECT * FROM pg_indexes WHERE indexname = :indexname", [':indexname' => $this->connection->getPrefix() . 'faking_table__test_field__idx'] )->fetchAll(); + $results = $this->connection->query("SELECT * FROM pg_indexes WHERE indexname = :indexname", [':indexname' => $this->connection->getPrefix() . 'faking_table__test_field__idx'])->fetchAll(); $this->assertCount(1, $results); $this->assertSame('testing_fake', $results[0]->schemaname); @@ -293,7 +292,7 @@ // @todo remove comments when: https://www.drupal.org/project/drupal/issues/3325358 is committed. // $this->assertTrue($this->connection->schema()->indexExists('faking_table', 'test_field')); - $results = $this->connection->query("SELECT * FROM pg_indexes WHERE indexname = :indexname", [':indexname' => $this->connection->getPrefix() . 'faking_table__test_field__key'] )->fetchAll(); + $results = $this->connection->query("SELECT * FROM pg_indexes WHERE indexname = :indexname", [':indexname' => $this->connection->getPrefix() . 'faking_table__test_field__key'])->fetchAll(); // Check the unique key columns. $this->assertCount(1, $results); @@ -301,7 +300,6 @@ $this->assertSame($this->connection->getPrefix() . 'faking_table', $results[0]->tablename); $this->assertStringContainsString('USING btree (test_field)', $results[0]->indexdef); - $this->connection->schema()->dropUniqueKey('faking_table', 'test_field'); // This function will not work due to a the fact that indexExist() does not search for keys without idx tag. @@ -362,2 +360,3 @@ } + }