public function Update::execute in Drupal 9
Same name in this branch
- 9 core/lib/Drupal/Core/Database/Query/Update.php \Drupal\Core\Database\Query\Update::execute()
- 9 core/lib/Drupal/Core/Database/Driver/pgsql/Update.php \Drupal\Core\Database\Driver\pgsql\Update::execute()
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Database/Query/Update.php \Drupal\Core\Database\Query\Update::execute()
Executes the UPDATE query.
Return value
The number of rows matched by the update query. This includes rows that actually didn't have to be updated because the values didn't change.
Overrides Query::execute
1 method overrides Update::execute()
- Update::execute in core/
lib/ Drupal/ Core/ Database/ Driver/ pgsql/ Update.php - Executes the UPDATE query.
File
- core/
lib/ Drupal/ Core/ Database/ Query/ Update.php, line 120
Class
- Update
- General class for an abstracted UPDATE operation.
Namespace
Drupal\Core\Database\QueryCode
public function execute() {
// Expressions take priority over literal fields, so we process those first
// and remove any literal fields that conflict.
$fields = $this->fields;
$update_values = [];
foreach ($this->expressionFields as $field => $data) {
if (!empty($data['arguments'])) {
$update_values += $data['arguments'];
}
if ($data['expression'] instanceof SelectInterface) {
$data['expression']
->compile($this->connection, $this);
$update_values += $data['expression']
->arguments();
}
unset($fields[$field]);
}
// Because we filter $fields the same way here and in __toString(), the
// placeholders will all match up properly.
$max_placeholder = 0;
foreach ($fields as $value) {
$update_values[':db_update_placeholder_' . $max_placeholder++] = $value;
}
if (count($this->condition)) {
$this->condition
->compile($this->connection, $this);
$update_values = array_merge($update_values, $this->condition
->arguments());
}
$stmt = $this->connection
->prepareStatement((string) $this, $this->queryOptions, TRUE);
try {
$stmt
->execute($update_values, $this->queryOptions);
return $stmt
->rowCount();
} catch (\Exception $e) {
$this->connection
->exceptionHandler()
->handleExecutionException($e, $stmt, $update_values, $this->queryOptions);
}
}