Skip to content
Snippets Groups Projects
Commit 468d201c authored by Dries Buytaert's avatar Dries Buytaert
Browse files

Patch #943042 by Damien Tournoud: MergeQuery regressions: key is used in the...

Patch #943042 by Damien Tournoud: MergeQuery regressions: key is used in the update query, exception is echoed.
parent da568f2a
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -908,8 +908,8 @@ public function __toString() { ...@@ -908,8 +908,8 @@ public function __toString() {
* instead. MergeQuery::fields() can also be called which calls both of these * instead. MergeQuery::fields() can also be called which calls both of these
* methods as the common case is to use the same column-value pairs for both * methods as the common case is to use the same column-value pairs for both
* INSERT and UPDATE. However, this is not mandatory. Another convinient * INSERT and UPDATE. However, this is not mandatory. Another convinient
* wrapper is MergeQuery::key() which adds the same column-value pairs to all * wrapper is MergeQuery::key() which adds the same column-value pairs to the
* three parts: the condition, the INSERT query part and the UPDATE query part. * condition and the INSERT query part.
* *
* Several methods (key(), fields(), insertFields()) can be called to set a * Several methods (key(), fields(), insertFields()) can be called to set a
* key-value pair for the INSERT query part. Subsequent calls for the same * key-value pair for the INSERT query part. Subsequent calls for the same
...@@ -1137,7 +1137,7 @@ public function fields(array $fields, array $values = array()) { ...@@ -1137,7 +1137,7 @@ public function fields(array $fields, array $values = array()) {
} }
/** /**
* Set the key field(s) to be used everywhere. * Set the key field(s) to be used as conditions for this query.
* *
* This method should only be called once. It may be called either * This method should only be called once. It may be called either
* with a single associative array or two indexed arrays. If called * with a single associative array or two indexed arrays. If called
...@@ -1146,9 +1146,8 @@ public function fields(array $fields, array $values = array()) { ...@@ -1146,9 +1146,8 @@ public function fields(array $fields, array $values = array()) {
* If called with two arrays, the first array is taken as the fields * If called with two arrays, the first array is taken as the fields
* and the second array is taken as the corresponding values. * and the second array is taken as the corresponding values.
* *
* The fields are copied to all three parts of the query: the condition, * The fields are copied to the condition of the query and the INSERT part.
* the UPDATE part and the INSERT part. If no other method is called, the * If no other method is called, the UPDATE will become a no-op.
* UPDATE will become a no-op.
* *
* @param $fields * @param $fields
* An array of fields to set. * An array of fields to set.
...@@ -1164,7 +1163,6 @@ public function key(array $fields, array $values = array()) { ...@@ -1164,7 +1163,6 @@ public function key(array $fields, array $values = array()) {
} }
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
$this->insertFields[$key] = $value; $this->insertFields[$key] = $value;
$this->updateFields[$key] = $value;
$this->condition($key, $value); $this->condition($key, $value);
} }
return $this; return $this;
...@@ -1226,7 +1224,6 @@ public function execute() { ...@@ -1226,7 +1224,6 @@ public function execute() {
return MergeQuery::STATUS_INSERT; return MergeQuery::STATUS_INSERT;
} }
catch (Exception $e) { catch (Exception $e) {
echo $e->getMessage();
// The insert query failed, maybe it's because a racing insert query // The insert query failed, maybe it's because a racing insert query
// beat us in inserting the same row. Retry the select query, if it // beat us in inserting the same row. Retry the select query, if it
// returns a row, ignore the error and continue with the update // returns a row, ignore the error and continue with the update
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment