function StatementPrefetchIterator::fetch

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Database/StatementPrefetchIterator.php \Drupal\Core\Database\StatementPrefetchIterator::fetch()

Overrides StatementInterface::fetch

7 calls to StatementPrefetchIterator::fetch()
StatementPrefetchIterator::fetchAll in core/lib/Drupal/Core/Database/StatementPrefetchIterator.php
Returns an array containing all of the result set rows.
StatementPrefetchIterator::fetchAllAssoc in core/lib/Drupal/Core/Database/StatementPrefetchIterator.php
Returns the result set as an associative array keyed by the given field.
StatementPrefetchIterator::fetchAllKeyed in core/lib/Drupal/Core/Database/StatementPrefetchIterator.php
Returns the entire result set as a single associative array.
StatementPrefetchIterator::fetchAssoc in core/lib/Drupal/Core/Database/StatementPrefetchIterator.php
Fetches the next row and returns it as an associative array.
StatementPrefetchIterator::fetchCol in core/lib/Drupal/Core/Database/StatementPrefetchIterator.php
Returns an entire single column of a result set as an indexed array.

... See full list

File

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

Class

StatementPrefetchIterator
An implementation of StatementInterface that prefetches all data.

Namespace

Drupal\Core\Database

Code

public function fetch($fetch_style = NULL, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset = NULL) {
    $currentKey = $this->getResultsetCurrentRowIndex();
    // We can remove the current record from the prefetched data, before
    // moving to the next record.
    unset($this->data[$currentKey]);
    $currentKey++;
    if (!isset($this->data[$currentKey])) {
        $this->markResultsetFetchingComplete();
        return FALSE;
    }
    // Now, format the next prefetched record according to the required fetch
    // style.
    // @todo in Drupal 11, remove arms for deprecated fetch modes.
    $rowAssoc = $this->data[$currentKey];
    $row = match ($fetch_style ?? $this->defaultFetchStyle) {    \PDO::FETCH_ASSOC => $rowAssoc,
        \PDO::FETCH_BOTH => $this->assocToBoth($rowAssoc),
        \PDO::FETCH_NUM => $this->assocToNum($rowAssoc),
        \PDO::FETCH_LAZY, \PDO::FETCH_OBJ => $this->assocToObj($rowAssoc),
        \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE => $this->assocToClassType($rowAssoc, $this->fetchOptions['constructor_args']),
        \PDO::FETCH_CLASS => $this->assocToClass($rowAssoc, $this->fetchOptions['class'], $this->fetchOptions['constructor_args']),
        \PDO::FETCH_INTO => $this->assocIntoObject($rowAssoc, $this->fetchOptions['object']),
        \PDO::FETCH_COLUMN => $this->assocToColumn($rowAssoc, $this->columnNames, $this->fetchOptions['column']),
        default => FALSE,
    
    };
    $this->setResultsetCurrentRow($row);
    return $row;
}

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