public function Update::execute

Same name in this branch
  1. 9.x drupal/core/lib/Drupal/Core/Database/Query/Update.php \Drupal\Core\Database\Query\Update::execute()
  2. 9.x drupal/core/lib/Drupal/Core/Database/Driver/sqlite/Update.php \Drupal\Core\Database\Driver\sqlite\Update::execute()
  3. 9.x drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Update.php \Drupal\Core\Database\Driver\pgsql\Update::execute()

Executes the UPDATE query.

Return value

The number of rows affected by the update.

Overrides Update::execute

File

drupal/core/lib/Drupal/Core/Database/Driver/sqlite/Update.php, line 48
Definition of Drupal\Core\Database\Driver\sqlite\Update

Class

Update
SQLite specific implementation of UpdateQuery.

Namespace

Drupal\Core\Database\Driver\sqlite

Code

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();
}