function StatementPrefetchIterator::execute
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Database/StatementPrefetchIterator.php \Drupal\Core\Database\StatementPrefetchIterator::execute()
- 10 core/lib/Drupal/Core/Database/StatementPrefetchIterator.php \Drupal\Core\Database\StatementPrefetchIterator::execute()
Overrides StatementBase::execute
1 call to StatementPrefetchIterator::execute()
- Statement::execute in core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Statement.php - Executes a prepared statement.
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 67
Class
- StatementPrefetchIterator
- An implementation of StatementInterface that prefetches all data.
Namespace
Drupal\Core\DatabaseCode
public function execute($args = [], $options = []) {
assert(!isset($options['fetch']) || $options['fetch'] instanceof FetchAs || is_string($options['fetch']), 'The "fetch" option passed to execute() must contain a FetchAs enum case or a string. See https://www.drupal.org/node/3488338');
$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);
// @phpstan-ignore unset.possiblyHookedProperty
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);
// @phpstan-ignore unset.possiblyHookedProperty
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.