Skip to content
Snippets Groups Projects
Commit 86a50988 authored by catch's avatar catch
Browse files

Issue #3230801 by alexpott, longwave, daffie, mondrake: Postgres does...

Issue #3230801 by alexpott, longwave, daffie, mondrake: Postgres does unnecessary work when writing a NULL to a blob field that triggers deprecations in PHP 8.1
parent c1ceedb7
No related branches found
No related tags found
14 merge requests!12227Issue #3181946 by jonmcl, mglaman,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -33,7 +33,7 @@ public function execute() {
$blob_count = 0;
foreach ($this->insertValues as $insert_values) {
foreach ($this->insertFields as $idx => $field) {
if (isset($table_information->blob_fields[$field])) {
if (isset($table_information->blob_fields[$field]) && $insert_values[$idx] !== NULL) {
$blobs[$blob_count] = fopen('php://memory', 'a');
fwrite($blobs[$blob_count], $insert_values[$idx]);
rewind($blobs[$blob_count]);
......
......@@ -47,7 +47,7 @@ public function execute() {
foreach ($fields as $field => $value) {
$placeholder = ':db_update_placeholder_' . ($max_placeholder++);
if (isset($table_information->blob_fields[$field])) {
if (isset($table_information->blob_fields[$field]) && $value !== NULL) {
$blobs[$blob_count] = fopen('php://memory', 'a');
fwrite($blobs[$blob_count], $value);
rewind($blobs[$blob_count]);
......
......@@ -29,7 +29,7 @@ public function execute() {
$blob_count = 0;
foreach ($this->insertValues as $insert_values) {
foreach ($this->insertFields as $idx => $field) {
if (isset($table_information->blob_fields[$field])) {
if (isset($table_information->blob_fields[$field]) && $insert_values[$idx] !== NULL) {
$blobs[$blob_count] = fopen('php://memory', 'a');
fwrite($blobs[$blob_count], $insert_values[$idx]);
rewind($blobs[$blob_count]);
......
......@@ -24,6 +24,17 @@ public function testInsertOneBlob() {
$this->assertSame($data, $r['blob1'], new FormattableMarkup('Can insert a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)]));
}
/**
* Tests that we can insert a null into blob field.
*/
public function testInsertNullBlob() {
$id = $this->connection->insert('test_one_blob')
->fields(['blob1' => NULL])
->execute();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertNull($r['blob1']);
}
/**
* Tests that we can insert multiple blob fields in the same query.
*/
......
......@@ -31,6 +31,24 @@ public function testUpdateOneBlob() {
$this->assertSame($data, $r['blob1'], new FormattableMarkup('Can update a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)]));
}
/**
* Tests that we can update a blob column to null.
*/
public function testUpdateNullBlob() {
$id = $this->connection->insert('test_one_blob')
->fields(['blob1' => 'test'])
->execute();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertSame('test', $r['blob1']);
$this->connection->update('test_one_blob')
->fields(['blob1' => NULL])
->condition('id', $id)
->execute();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertNull($r['blob1']);
}
/**
* Confirms that we can update two blob columns in the same table.
*/
......
......@@ -122,4 +122,26 @@ public function testUpsertNonExistingTable(): void {
$upsert->execute();
}
/**
* Tests that we can upsert a null into blob field.
*/
public function testUpsertNullBlob() {
$id = $this->connection->insert('test_one_blob')
->fields(['blob1' => 'test'])
->execute();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertSame('test', $r['blob1']);
$this->connection->upsert('test_one_blob')
->key('id')
->fields(['id', 'blob1'])
->values(['id' => $id, 'blob1' => NULL])
->values(['id' => $id + 1, 'blob1' => NULL])
->execute();
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id])->fetchAssoc();
$this->assertNull($r['blob1']);
$r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE [id] = :id', [':id' => $id + 1])->fetchAssoc();
$this->assertNull($r['blob1']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment