You are here

public function Update::execute in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Update.php \Drupal\Driver\Database\sqlsrv\Update::execute()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Update.php \Drupal\Driver\Database\sqlsrv\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 Update::execute

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Update.php, line 17

Class

Update
Sqlsvr implementation of \Drupal\Core\Database\Query\Update.

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function execute() {

  // Retrieve query options.
  $options = $this->queryOptions;

  // Fetch the list of blobs and sequences used on that table.

  /** @var \Drupal\Driver\Database\sqlsrv\Schema $schema */
  $schema = $this->connection
    ->schema();
  $columnInformation = $schema
    ->queryColumnInformation($this->table);

  // Because we filter $fields the same way here and in __toString(), the
  // placeholders will all match up properly.

  /** @var \Drupal\Core\Database\Statement $stmt */
  $stmt = $this->connection
    ->prepareQuery((string) $this);

  // Expressions take priority over literal fields, so we process those first
  // and remove any literal fields that conflict.
  $fields = $this->fields;
  foreach ($this->expressionFields as $field => $data) {
    if (!empty($data['arguments'])) {
      foreach ($data['arguments'] as $placeholder => $argument) {

        // We assume that an expression will never happen on a BLOB field,
        // which is a fairly safe assumption to make since in most cases
        // it would be an invalid query anyway.
        $stmt
          ->bindParam($placeholder, $data['arguments'][$placeholder]);
      }
    }
    if ($data['expression'] instanceof SelectInterface) {
      $data['expression']
        ->compile($this->connection, $this);
      $select_query_arguments = $data['expression']
        ->arguments();
      foreach ($select_query_arguments as $placeholder => $argument) {
        $stmt
          ->bindParam($placeholder, $select_query_arguments[$placeholder]);
      }
    }
    unset($fields[$field]);
  }

  // We use this array to store references to the blob handles.
  // This is necessary because the PDO will otherwise messes up with
  // references.
  $blobs = [];
  Utils::bindValues($stmt, $fields, $blobs, ':db_update_placeholder_', $columnInformation);

  // Add conditions.
  if (count($this->condition)) {
    $this->condition
      ->compile($this->connection, $this);
    $arguments = $this->condition
      ->arguments();
    Utils::bindArguments($stmt, $arguments);
  }
  $options = $this->queryOptions;
  $options['already_prepared'] = TRUE;
  $options['return'] = Database::RETURN_AFFECTED;
  return $this->connection
    ->query($stmt, [], $options);
}