You are here

public function UpdateQuery_sqlsrv::execute in Drupal driver for SQL Server and SQL Azure 7.2

Same name and namespace in other branches
  1. 7.3 sqlsrv/query.inc \UpdateQuery_sqlsrv::execute()
  2. 7 sqlsrv/query.inc \UpdateQuery_sqlsrv::execute()

Executes the UPDATE query.

Return value

The number of rows affected by the update.

Overrides UpdateQuery::execute

File

sqlsrv/query.inc, line 266

Class

UpdateQuery_sqlsrv
SQL Server-specific implementation of UPDATE.

Code

public function execute() {

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

  // Fetch the list of blobs and sequences used on that table.
  $columnInformation = $this->connection
    ->schema()
    ->queryColumnInformation($this->table);

  // MySQL is a pretty slut that swallows everything thrown at it,
  // like trying to update an identity field...
  if (isset($columnInformation['identity']) && isset($this->fields[$columnInformation['identity']])) {
    unset($this->fields[$columnInformation['identity']]);
  }

  // Because we filter $fields the same way here and in __toString(), the
  // placeholders will all match up properly.
  $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;
  DatabaseUtils::BindExpressions($stmt, $this->expressionFields, $fields);

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

  // Add conditions.
  if (count($this->condition)) {
    $this->condition
      ->compile($this->connection, $this);
    $arguments = $this->condition
      ->arguments();
    DatabaseUtils::BindArguments($stmt, $arguments);
  }
  $options = $this->queryOptions;
  $options['already_prepared'] = TRUE;

  // Run the statement.
  $this->connection
    ->query($stmt, array(), $options);
  return $stmt
    ->rowCount();
}