public function Update::execute in Drupal driver for SQL Server and SQL Azure 4.2.x
Same name and namespace in other branches
- 3.1.x src/Driver/Database/sqlsrv/Update.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Update::execute()
- 4.0.x src/Driver/Database/sqlsrv/Update.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Update::execute()
- 4.1.x src/Driver/Database/sqlsrv/Update.php \Drupal\sqlsrv\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
- src/
Driver/ Database/ sqlsrv/ Update.php, line 17
Class
- Update
- Sqlsvr implementation of \Drupal\Core\Database\Query\Update.
Namespace
Drupal\sqlsrv\Driver\Database\sqlsrvCode
public function execute() {
// Retrieve query options.
$options = $this->queryOptions;
// Fetch the list of blobs and sequences used on that table.
/** @var \Drupal\sqlsrv\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
->prepareStatement((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
->getClientStatement()
->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
->getClientStatement()
->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 $stmt
->execute(NULL, $options);
}