function StatementPrefetchIterator::execute

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Database/StatementPrefetchIterator.php \Drupal\Core\Database\StatementPrefetchIterator::execute()

Overrides StatementBase::execute

1 method overrides StatementPrefetchIterator::execute()
Statement::execute in core/modules/sqlite/src/Driver/Database/sqlite/Statement.php
Executes a prepared statement.

File

core/lib/Drupal/Core/Database/StatementPrefetchIterator.php, line 121

Class

StatementPrefetchIterator
An implementation of StatementInterface that prefetches all data.

Namespace

Drupal\Core\Database

Code

public function execute($args = [], $options = []) {
  if (isset($options['fetch']) && is_int($options['fetch'])) {
    @trigger_error("Passing the 'fetch' key as an integer to \$options in execute() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \\Drupal\\Core\\Database\\Statement\\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
  }
  $startEvent = $this->dispatchStatementExecutionStartEvent($args ?? []);
  // Prepare and execute the statement.
  try {
    $this->clientStatement = $this->getStatement($this->queryString, $args);
    $return = $this->clientExecute($args, $options);
  } catch (\Exception $e) {
    $this->dispatchStatementExecutionFailureEvent($startEvent, $e);
    unset($this->clientStatement);
    throw $e;
  }
  // Fetch all the data from the reply, in order to release any lock as soon
  // as possible. Then, destroy the client statement. See the documentation
  // of \Drupal\sqlite\Driver\Database\sqlite\Statement for an explanation.
  $this->result = new PrefetchedResult($this->fetchMode, $this->fetchOptions, $this->clientFetchAll(FetchAs::Associative), $this->rowCountEnabled ? $this->clientRowCount() : NULL);
  unset($this->clientStatement);
  $this->markResultsetIterable($return);
  if (isset($options['fetch'])) {
    if (is_string($options['fetch'])) {
      // Default to an object. Note: db fields will be added to the object
      // before the constructor is run. If you need to assign fields after
      // the constructor is run. See https://www.drupal.org/node/315092.
      $this->setFetchMode(FetchAs::ClassObject, $options['fetch']);
    }
    else {
      $this->setFetchMode($options['fetch']);
    }
  }
  $this->dispatchStatementExecutionEndEvent($startEvent);
  return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.