class StatementWrapperIterator
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Database/StatementWrapperIterator.php \Drupal\Core\Database\StatementWrapperIterator
- 10 core/lib/Drupal/Core/Database/StatementWrapperIterator.php \Drupal\Core\Database\StatementWrapperIterator
StatementInterface iterator implementation.
Hierarchy
- class \Drupal\Core\Database\Statement\StatementBase implements \Drupal\Core\Database\Statement\Iterator, \Drupal\Core\Database\StatementInterface uses \Drupal\Core\Database\FetchModeTrait, \Drupal\Core\Database\StatementIteratorTrait
- class \Drupal\Core\Database\StatementWrapperIterator uses \Drupal\Core\Database\Statement\PdoTrait extends \Drupal\Core\Database\Statement\StatementBase
Expanded class hierarchy of StatementWrapperIterator
3 files declare their use of StatementWrapperIterator
- Connection.php in core/
modules/ mysql/ src/ Driver/ Database/ mysql/ Connection.php - Connection.php in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Connection.php - StubConnection.php in core/
tests/ Drupal/ Tests/ Core/ Database/ Stub/ StubConnection.php
File
-
core/
lib/ Drupal/ Core/ Database/ StatementWrapperIterator.php, line 13
Namespace
Drupal\Core\DatabaseView source
class StatementWrapperIterator extends StatementBase {
use PdoTrait;
/**
* Constructs a StatementWrapperIterator object.
*
* @param \Drupal\Core\Database\Connection $connection
* Drupal database connection object.
* @param object $clientConnection
* Client database connection object, for example \PDO.
* @param string $query
* The SQL query string.
* @param array $options
* Array of query options.
* @param bool $rowCountEnabled
* (optional) Enables counting the rows matched. Defaults to FALSE.
*/
public function __construct(Connection $connection, object $clientConnection, string $query, array $options, bool $rowCountEnabled = FALSE) {
parent::__construct($connection, $clientConnection, $query, $rowCountEnabled);
$this->clientStatement = $this->clientConnection
->prepare($query, $options);
$this->setFetchMode(FetchAs::Object);
}
/**
* Returns the client-level database PDO statement object.
*
* This method should normally be used only within database driver code.
*
* @return \PDOStatement
* The client-level database PDO statement.
*
* @throws \RuntimeException
* If the client-level statement is not set.
*/
public function getClientStatement() : \PDOStatement {
if (isset($this->clientStatement)) {
assert($this->clientStatement instanceof \PDOStatement);
return $this->clientStatement;
}
throw new \LogicException('\\PDOStatement not initialized');
}
/**
* {@inheritdoc}
*/
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');
if (isset($options['fetch'])) {
if (is_string($options['fetch'])) {
$this->setFetchMode(FetchAs::ClassObject, $options['fetch']);
}
else {
$this->setFetchMode($options['fetch']);
}
}
$startEvent = $this->dispatchStatementExecutionStartEvent($args ?? []);
try {
$return = $this->clientExecute($args, $options);
$this->result = new PdoResult($this->fetchMode, $this->fetchOptions, $this->getClientStatement());
$this->markResultsetIterable($return);
} catch (\Exception $e) {
$this->dispatchStatementExecutionFailureEvent($startEvent, $e);
throw $e;
}
$this->dispatchStatementExecutionEndEvent($startEvent);
return $return;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.