Upsert::preExecute always returns TRUE which leads to Exception on empty insert

Created on 27 May 2024, 7 months ago
Updated 28 May 2024, 7 months ago

Problem/Motivation

Upsert queries work similarly to Insert queries, except that they update existing records. When executing an Insert query without values, preExecute() returns FALSE because executing the query without values to insert is rather useless.
Running an Upsert queries without values though, throws an Exception:

Steps to reproduce

Run the following code (schema in the example taken from Drupal\KernelTests\Core\Database\UpsertTest):

<?php
$connection = Database::getConnection();

// Define fields only but no values.
$upsert = $connection->upsert('test_people')
  ->key('job')
  ->fields(['job', 'age', 'name']);

$upsert->execute();
?>

This will result in the error noted above.

Proposed resolution

Update Upsert::preExecute() to behave similar to Insert::preExecute() so the query does nothing if no values are given.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Database 

Last updated 2 days ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇩🇪Germany stborchert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024