diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php index 3ba9748bcdded287d10328d56dada9fa6d45124c..325ffe95d14161fe102f090e8b46558e78254523 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php @@ -184,15 +184,6 @@ public static function open(array &$connection_options = []) { public function query($query, array $args = [], $options = []) { $options += $this->defaultOptions(); - // The PDO PostgreSQL driver has a bug which doesn't type cast booleans - // correctly when parameters are bound using associative arrays. - // @see http://bugs.php.net/bug.php?id=48383 - foreach ($args as &$value) { - if (is_bool($value)) { - $value = (int) $value; - } - } - // We need to wrap queries with a savepoint if: // - Currently in a transaction. // - A 'mimic_implicit_commit' does not exist already. diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php index c1bc2f8ee2557ea8896e1caa70d2f999e90f3960..0f398f0af121a94f46958e52d8c166c74d8b4f84 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Database\IntegrityConstraintViolationException; /** @@ -232,4 +233,66 @@ public function testInsertIntegrityViolation() { ->execute(); } + /** + * Tests if inserting boolean to integer field works. + */ + public function testInsertBooleanToIntegerField() { + // @todo Remove this when https://www.drupal.org/i/3360420 drops. + if ($this->connection->databaseType() == 'sqlite') { + $this->markTestSkipped('SQLite does not use strict tables.'); + } + $table_specification = [ + 'fields' => [ + 'id' => [ + 'type' => 'int', + 'not null' => TRUE, + ], + 'test_field_1' => [ + 'type' => 'int', + ], + ], + 'primary key' => ['id'], + ]; + + $this->connection->schema()->createTable('insert_bool', $table_specification); + + $this->expectException(DatabaseExceptionWrapper::class); + $this->connection->insert('insert_bool') + ->fields(['id' => 1, 'test_field_1' => FALSE]) + ->execute(); + + // We should not have any rows in this table. + $this->assertEquals(0, $this->connection->select('insert_bool')->countQuery()->execute()->fetchField()); + } + + /** + * Tests if inserting boolean to integer field works using a query. + */ + public function testQueryInsertBooleanToIntegerField() { + // @todo Remove this when https://www.drupal.org/i/3360420 drops. + if ($this->connection->databaseType() == 'sqlite') { + $this->markTestSkipped('SQLite does not use strict tables.'); + } + $table_specification = [ + 'fields' => [ + 'id' => [ + 'type' => 'int', + 'not null' => TRUE, + ], + 'test_field_1' => [ + 'type' => 'int', + ], + ], + 'primary key' => ['id'], + ]; + + $this->connection->schema()->createTable('insert_bool', $table_specification); + + $this->expectException(DatabaseExceptionWrapper::class); + $this->connection->query('INSERT INTO {insert_bool} (id,test_field_1) VALUES (:id, :test_field_1)', [':id' => 1, ':test_field_1' => FALSE]); + + // We should not have any rows in this table. + $this->assertEquals(0, $this->connection->select('insert_bool')->countQuery()->execute()->fetchField()); + } + }