From b78ae9ef49a6db9b704b32e0d5f45062a63b4ba8 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Fri, 21 Jul 2023 18:09:48 +0200
Subject: [PATCH] Issue #3357454 by Arantxio, daffie: Remove bugfix for PHP bug
 48383

---
 .../src/Driver/Database/pgsql/Connection.php  |  9 ---
 .../KernelTests/Core/Database/InsertTest.php  | 63 +++++++++++++++++++
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php
index 3ba9748bcdde..325ffe95d141 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 c1bc2f8ee255..0f398f0af121 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());
+  }
+
 }
-- 
GitLab