You are here

class StatementEmpty in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Database/StatementEmpty.php \Drupal\Core\Database\StatementEmpty

Empty implementation of a database statement.

This class satisfies the requirements of being a database statement/result object, but does not actually contain data. It is useful when developers need to safely return an "empty" result set without connecting to an actual database. Calling code can then treat it the same as if it were an actual result set that happens to contain no records.

Hierarchy

Expanded class hierarchy of StatementEmpty

See also

\Drupal\search\SearchQuery

2 files declare their use of StatementEmpty
EmptyStatementTest.php in core/tests/Drupal/Tests/Core/Database/EmptyStatementTest.php
Contains \Drupal\Tests\Core\Database\EmptyStatementTest.
StubConnection.php in core/tests/Drupal/Tests/Core/Database/Stub/StubConnection.php
Contains \Drupal\Tests\Core\Database\Stub\StubConnection.

File

core/lib/Drupal/Core/Database/StatementEmpty.php, line 22
Contains \Drupal\Core\Database\StatementEmpty.

Namespace

Drupal\Core\Database
View source
class StatementEmpty implements \Iterator, StatementInterface {

  /**
   * Is rowCount() execution allowed.
   *
   * @var bool
   */
  public $allowRowCount = FALSE;

  /**
   * {@inheritdoc}
   */
  public function execute($args = array(), $options = array()) {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getQueryString() {
    return '';
  }

  /**
   * {@inheritdoc}
   */
  public function rowCount() {
    if ($this->allowRowCount) {
      return 0;
    }
    throw new RowCountException();
  }

  /**
   * {@inheritdoc}
   */
  public function setFetchMode($mode, $a1 = NULL, $a2 = array()) {
    return;
  }

  /**
   * {@inheritdoc}
   */
  public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function fetchField($index = 0) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function fetchObject() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function fetchAssoc() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function fetchAll($mode = NULL, $column_index = NULL, $constructor_arguments = NULL) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function fetchCol($index = 0) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function fetchAllKeyed($key_index = 0, $value_index = 1) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function fetchAllAssoc($key, $fetch = NULL) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function current() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function key() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function rewind() {

    // Nothing to do: our DatabaseStatement can't be rewound.
  }

  /**
   * {@inheritdoc}
   */
  public function next() {

    // Do nothing, since this is an always-empty implementation.
  }

  /**
   * {@inheritdoc}
   */
  public function valid() {
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StatementEmpty::$allowRowCount public property Is rowCount() execution allowed.
StatementEmpty::current public function
StatementEmpty::execute public function Executes a prepared statement Overrides StatementInterface::execute
StatementEmpty::fetch public function Fetches the next row from a result set. Overrides StatementInterface::fetch
StatementEmpty::fetchAll public function Returns an array containing all of the result set rows. Overrides StatementInterface::fetchAll
StatementEmpty::fetchAllAssoc public function Returns the result set as an associative array keyed by the given field. Overrides StatementInterface::fetchAllAssoc
StatementEmpty::fetchAllKeyed public function Returns the entire result set as a single associative array. Overrides StatementInterface::fetchAllKeyed
StatementEmpty::fetchAssoc public function Fetches the next row and returns it as an associative array. Overrides StatementInterface::fetchAssoc
StatementEmpty::fetchCol public function Returns an entire single column of a result set as an indexed array. Overrides StatementInterface::fetchCol
StatementEmpty::fetchField public function Returns a single field from the next record of a result set. Overrides StatementInterface::fetchField
StatementEmpty::fetchObject public function Fetches the next row and returns it as an object. Overrides StatementInterface::fetchObject
StatementEmpty::getQueryString public function Gets the query string of this statement. Overrides StatementInterface::getQueryString
StatementEmpty::key public function
StatementEmpty::next public function
StatementEmpty::rewind public function
StatementEmpty::rowCount public function Returns the number of rows affected by the last SQL statement. Overrides StatementInterface::rowCount
StatementEmpty::setFetchMode public function Sets the default fetch mode for this statement. Overrides StatementInterface::setFetchMode
StatementEmpty::valid public function