SQLite specific implementation of UpdateQuery.
SQLite counts all the rows that match the conditions as modified, even if they will not be affected by the query. We workaround this by ensuring that we don't select those rows.
A query like this one: UPDATE test SET name = 'newname' WHERE tid = 1 will become: UPDATE test SET name = 'newname' WHERE tid = 1 AND name <> 'newname'
Expanded class hierarchy of Update
class Update extends QueryUpdate {
/**
* Helper function that removes the fields that are already in a condition.
*
* @param $fields
* The fields.
* @param QueryConditionInterface $condition
* A database condition.
*/
protected function removeFieldsInCondition(&$fields, ConditionInterface $condition) {
foreach ($condition
->conditions() as $child_condition) {
if (isset($child_condition['field'])) {
if ($child_condition['field'] instanceof ConditionInterface) {
$this
->removeFieldsInCondition($fields, $child_condition['field']);
}
else {
unset($fields[$child_condition['field']]);
}
}
}
}
public function execute() {
if (!empty($this->queryOptions['sqlite_return_matched_rows'])) {
return parent::execute();
}
// Get the fields used in the update query, and remove those that are already
// in the condition.
$fields = $this->expressionFields + $this->fields;
$this
->removeFieldsInCondition($fields, $this->condition);
// Add the inverse of the fields to the condition.
$condition = new Condition('OR');
foreach ($fields as $field => $data) {
if (is_array($data)) {
// The field is an expression.
$condition
->where($field . ' <> ' . $data['expression']);
$condition
->isNull($field);
}
elseif (!isset($data)) {
// The field will be set to NULL.
$condition
->isNotNull($field);
}
else {
$condition
->condition($field, $data, '<>');
$condition
->isNull($field);
}
}
if (count($condition)) {
$condition
->compile($this->connection, $this);
$this->condition
->where((string) $condition, $condition
->arguments());
}
return parent::execute();
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Query:: |
protected | property | An array of comments that can be prepended to a query. | |
Query:: |
protected | property | The connection object on which to run this query. | |
Query:: |
protected | property | The key of the connection object. | |
Query:: |
protected | property | The target of the connection object. | |
Query:: |
protected | property | The placeholder counter. | |
Query:: |
protected | property | The query options to pass on to the connection object. | |
Query:: |
protected | property | A unique identifier for this query object. | |
Query:: |
public | function | Adds a comment to the query. | |
Query:: |
public | function | Returns a reference to the comments array for the query. | |
Query:: |
public | function |
Gets the next placeholder value for this query object. Overrides PlaceholderInterface:: |
|
Query:: |
public | function |
Returns a unique identifier for this object. Overrides PlaceholderInterface:: |
|
Query:: |
public | function | Implements the magic __clone function. | 1 |
Query:: |
public | function | Implements the magic __sleep function to disconnect from the database. | |
Query:: |
public | function | Implements the magic __wakeup function to reconnect to the database. | |
Update:: |
protected | property | An array of values to update to. | |
Update:: |
protected | property | The condition object for this query. | |
Update:: |
protected | property | Array of fields to update to an expression in case of a duplicate record. | |
Update:: |
protected | property | An array of fields that will be updated. | |
Update:: |
protected | property | The table to update. | |
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::arguments(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::compile(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::compiled(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::condition(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::conditions(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Executes the UPDATE query. Overrides Update:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::exists(). Overrides ConditionInterface:: |
|
Update:: |
public | function | Specifies fields to be updated as an expression. | |
Update:: |
public | function | Adds a set of field->value pairs to be updated. | |
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::isNull(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::notExists(). Overrides ConditionInterface:: |
|
Update:: |
protected | function | Helper function that removes the fields that are already in a condition. | |
Update:: |
public | function |
Implements Drupal\Core\Database\Query\ConditionInterface::where(). Overrides ConditionInterface:: |
|
Update:: |
public | function |
Constructs an Update query object. Overrides Query:: |
|
Update:: |
public | function |
Implements PHP magic __toString method to convert the query to a string. Overrides Query:: |