Issue #3357454 by Arantxio, daffie: Remove bugfix for PHP bug 48383
parent
f46ed65a7c
commit
b78ae9ef49
|
@ -184,15 +184,6 @@ class Connection extends DatabaseConnection implements SupportsTemporaryTablesIn
|
|||
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.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Database;
|
||||
|
||||
use Drupal\Core\Database\DatabaseExceptionWrapper;
|
||||
use Drupal\Core\Database\IntegrityConstraintViolationException;
|
||||
|
||||
/**
|
||||
|
@ -232,4 +233,66 @@ class InsertTest extends DatabaseTestBase {
|
|||
->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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue