class SelectExtender

The base extender class for Select queries.

Hierarchy

Expanded class hierarchy of SelectExtender

4 files declare their use of SelectExtender
node.module in drupal/core/modules/node/node.module
The core module that allows content to be submitted to the site.
PagerSelectExtender.php in drupal/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php
Definition of Drupal\Core\Database\Query\PagerSelectExtender
SearchQuery.php in drupal/core/modules/search/lib/Drupal/search/SearchQuery.php
Definition of Drupal\search\SearchQuery.
tablesort.inc in drupal/core/includes/tablesort.inc
Functions to aid in the creation of sortable tables.

File

drupal/core/lib/Drupal/Core/Database/Query/SelectExtender.php, line 15
Definition of Drupal\Core\Database\Query\SelectExtender

Namespace

Drupal\Core\Database\Query
View source
class SelectExtender implements SelectInterface {

  /**
   * The Select query object we are extending/decorating.
   *
   * @var Drupal\Core\Database\Query\SelectInterface
   */
  protected $query;

  /**
   * The connection object on which to run this query.
   *
   * @var DatabaseConnection
   */
  protected $connection;

  /**
   * A unique identifier for this query object.
   */
  protected $uniqueIdentifier;

  /**
   * The placeholder counter.
   */
  protected $placeholder = 0;
  public function __construct(SelectInterface $query, Connection $connection) {
    $this->uniqueIdentifier = uniqid('', TRUE);
    $this->query = $query;
    $this->connection = $connection;
  }

  /**
   * Implements Drupal\Core\Database\Query\PlaceholderInterface::uniqueIdentifier().
   */
  public function uniqueIdentifier() {
    return $this->uniqueIdentifier;
  }

  /**
   * Implements Drupal\Core\Database\Query\PlaceholderInterface::nextPlaceholder().
   */
  public function nextPlaceholder() {
    return $this->placeholder++;
  }

  /* Implementations of Drupal\Core\Database\Query\AlterableInterface. */
  public function addTag($tag) {
    $this->query
      ->addTag($tag);
    return $this;
  }
  public function hasTag($tag) {
    return $this->query
      ->hasTag($tag);
  }
  public function hasAllTags() {
    return call_user_func_array(array(
      $this->query,
      'hasAllTags',
    ), func_get_args());
  }
  public function hasAnyTag() {
    return call_user_func_array(array(
      $this->query,
      'hasAnyTags',
    ), func_get_args());
  }
  public function addMetaData($key, $object) {
    $this->query
      ->addMetaData($key, $object);
    return $this;
  }
  public function getMetaData($key) {
    return $this->query
      ->getMetaData($key);
  }

  /* Implementations of Drupal\Core\Database\Query\ConditionInterface for the WHERE clause. */
  public function condition($field, $value = NULL, $operator = NULL) {
    $this->query
      ->condition($field, $value, $operator);
    return $this;
  }
  public function &conditions() {
    return $this->query
      ->conditions();
  }
  public function arguments() {
    return $this->query
      ->arguments();
  }
  public function where($snippet, $args = array()) {
    $this->query
      ->where($snippet, $args);
    return $this;
  }
  public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
    return $this->query
      ->compile($connection, $queryPlaceholder);
  }
  public function compiled() {
    return $this->query
      ->compiled();
  }

  /* Implementations of Drupal\Core\Database\Query\ConditionInterface for the HAVING clause. */
  public function havingCondition($field, $value = NULL, $operator = '=') {
    $this->query
      ->havingCondition($field, $value, $operator);
    return $this;
  }
  public function &havingConditions() {
    return $this->query
      ->havingConditions();
  }
  public function havingArguments() {
    return $this->query
      ->havingArguments();
  }
  public function having($snippet, $args = array()) {
    $this->query
      ->having($snippet, $args);
    return $this;
  }
  public function havingCompile(Connection $connection) {
    return $this->query
      ->havingCompile($connection);
  }

  /* Implementations of Drupal\Core\Database\Query\ExtendableInterface. */
  public function extend($extender_name) {
    $class = $this->connection
      ->getDriverClass($extender_name);
    return new $class($this, $this->connection);
  }

  /* Alter accessors to expose the query data to alter hooks. */
  public function &getFields() {
    return $this->query
      ->getFields();
  }
  public function &getExpressions() {
    return $this->query
      ->getExpressions();
  }
  public function &getOrderBy() {
    return $this->query
      ->getOrderBy();
  }
  public function &getGroupBy() {
    return $this->query
      ->getGroupBy();
  }
  public function &getTables() {
    return $this->query
      ->getTables();
  }
  public function &getUnion() {
    return $this->query
      ->getUnion();
  }
  public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
    return $this->query
      ->getArguments($queryPlaceholder);
  }
  public function isPrepared() {
    return $this->query
      ->isPrepared();
  }
  public function preExecute(SelectInterface $query = NULL) {

    // If no query object is passed in, use $this.
    if (!isset($query)) {
      $query = $this;
    }
    return $this->query
      ->preExecute($query);
  }
  public function execute() {

    // By calling preExecute() here, we force it to preprocess the extender
    // object rather than just the base query object.  That means
    // hook_query_alter() gets access to the extended object.
    if (!$this
      ->preExecute($this)) {
      return NULL;
    }
    return $this->query
      ->execute();
  }
  public function distinct($distinct = TRUE) {
    $this->query
      ->distinct($distinct);
    return $this;
  }
  public function addField($table_alias, $field, $alias = NULL) {
    return $this->query
      ->addField($table_alias, $field, $alias);
  }
  public function fields($table_alias, array $fields = array()) {
    $this->query
      ->fields($table_alias, $fields);
    return $this;
  }
  public function addExpression($expression, $alias = NULL, $arguments = array()) {
    return $this->query
      ->addExpression($expression, $alias, $arguments);
  }
  public function join($table, $alias = NULL, $condition = NULL, $arguments = array()) {
    return $this->query
      ->join($table, $alias, $condition, $arguments);
  }
  public function innerJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) {
    return $this->query
      ->innerJoin($table, $alias, $condition, $arguments);
  }
  public function leftJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) {
    return $this->query
      ->leftJoin($table, $alias, $condition, $arguments);
  }
  public function rightJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) {
    return $this->query
      ->rightJoin($table, $alias, $condition, $arguments);
  }
  public function addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = array()) {
    return $this->query
      ->addJoin($type, $table, $alias, $condition, $arguments);
  }
  public function orderBy($field, $direction = 'ASC') {
    $this->query
      ->orderBy($field, $direction);
    return $this;
  }
  public function orderRandom() {
    $this->query
      ->orderRandom();
    return $this;
  }
  public function range($start = NULL, $length = NULL) {
    $this->query
      ->range($start, $length);
    return $this;
  }
  public function union(SelectInterface $query, $type = '') {
    $this->query
      ->union($query, $type);
    return $this;
  }
  public function groupBy($field) {
    $this->query
      ->groupBy($field);
    return $this;
  }
  public function forUpdate($set = TRUE) {
    $this->query
      ->forUpdate($set);
    return $this;
  }
  public function countQuery() {
    return $this->query
      ->countQuery();
  }
  function isNull($field) {
    $this->query
      ->isNull($field);
    return $this;
  }
  function isNotNull($field) {
    $this->query
      ->isNotNull($field);
    return $this;
  }
  public function exists(SelectInterface $select) {
    $this->query
      ->exists($select);
    return $this;
  }
  public function notExists(SelectInterface $select) {
    $this->query
      ->notExists($select);
    return $this;
  }
  public function __toString() {
    return (string) $this->query;
  }
  public function __clone() {
    $this->uniqueIdentifier = uniqid('', TRUE);

    // We need to deep-clone the query we're wrapping, which in turn may
    // deep-clone other objects.  Exciting!
    $this->query = clone $this->query;
  }

  /**
   * Magic override for undefined methods.
   *
   * If one extender extends another extender, then methods in the inner extender
   * will not be exposed on the outer extender.  That's because we cannot know
   * in advance what those methods will be, so we cannot provide wrapping
   * implementations as we do above.  Instead, we use this slower catch-all method
   * to handle any additional methods.
   */
  public function __call($method, $args) {
    $return = call_user_func_array(array(
      $this->query,
      $method,
    ), $args);

    // Some methods will return the called object as part of a fluent interface.
    // Others will return some useful value.  If it's a value, then the caller
    // probably wants that value.  If it's the called object, then we instead
    // return this object.  That way we don't "lose" an extender layer when
    // chaining methods together.
    if ($return instanceof SelectInterface) {
      return $this;
    }
    else {
      return $return;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SelectExtender::$connection protected property The connection object on which to run this query.
SelectExtender::$placeholder protected property The placeholder counter.
SelectExtender::$query protected property The Select query object we are extending/decorating.
SelectExtender::$uniqueIdentifier protected property A unique identifier for this query object.
SelectExtender::addExpression public function Adds an expression to the list of "fields" to be SELECTed. Overrides SelectInterface::addExpression
SelectExtender::addField public function Adds a field to the list to be SELECTed. Overrides SelectInterface::addField
SelectExtender::addJoin public function Join against another table in the database. Overrides SelectInterface::addJoin
SelectExtender::addMetaData public function Adds additional metadata to the query. Overrides AlterableInterface::addMetaData
SelectExtender::addTag public function Adds a tag to a query. Overrides AlterableInterface::addTag
SelectExtender::arguments public function Gets a complete list of all values to insert into the prepared statement. Overrides ConditionInterface::arguments
SelectExtender::compile public function Compiles the saved conditions for later retrieval. Overrides ConditionInterface::compile
SelectExtender::compiled public function Check whether a condition has been previously compiled. Overrides ConditionInterface::compiled
SelectExtender::condition public function Helper function: builds the most common conditional clauses. Overrides ConditionInterface::condition
SelectExtender::conditions public function Gets a complete list of all conditions in this conditional clause. Overrides ConditionInterface::conditions 1
SelectExtender::countQuery public function Get the equivalent COUNT query of this query as a new query object. Overrides SelectInterface::countQuery 1
SelectExtender::distinct public function Sets this query to be DISTINCT. Overrides SelectInterface::distinct
SelectExtender::execute public function 2
SelectExtender::exists public function Sets a condition that the specified subquery returns values. Overrides ConditionInterface::exists
SelectExtender::extend public function Enhance this object by wrapping it in an extender object. Overrides ExtendableInterface::extend
SelectExtender::fields public function Add multiple fields from the same table to be SELECTed. Overrides SelectInterface::fields
SelectExtender::forUpdate public function Add FOR UPDATE to the query. Overrides SelectInterface::forUpdate
SelectExtender::getArguments public function Compiles and returns an associative array of the arguments for this prepared statement. Overrides SelectInterface::getArguments
SelectExtender::getExpressions public function Returns a reference to the expressions array for this query. Overrides SelectInterface::getExpressions
SelectExtender::getFields public function Returns a reference to the fields array for this query. Overrides SelectInterface::getFields
SelectExtender::getGroupBy public function Returns a reference to the group-by array for this query. Overrides SelectInterface::getGroupBy
SelectExtender::getMetaData public function Retrieves a given piece of metadata. Overrides AlterableInterface::getMetaData
SelectExtender::getOrderBy public function Returns a reference to the order by array for this query. Overrides SelectInterface::getOrderBy
SelectExtender::getTables public function Returns a reference to the tables array for this query. Overrides SelectInterface::getTables
SelectExtender::getUnion public function Returns a reference to the union queries for this query. This include queries for UNION, UNION ALL, and UNION DISTINCT. Overrides SelectInterface::getUnion
SelectExtender::groupBy public function Groups the result set by the specified field. Overrides SelectInterface::groupBy
SelectExtender::hasAllTags public function Determines if a given query has all specified tags. Overrides AlterableInterface::hasAllTags
SelectExtender::hasAnyTag public function Determines if a given query has any specified tag. Overrides AlterableInterface::hasAnyTag
SelectExtender::hasTag public function Determines if a given query has a given tag. Overrides AlterableInterface::hasTag
SelectExtender::having public function
SelectExtender::havingArguments public function
SelectExtender::havingCompile public function
SelectExtender::havingCondition public function Helper function to build most common HAVING conditional clauses. Overrides SelectInterface::havingCondition
SelectExtender::havingConditions public function
SelectExtender::innerJoin public function Inner Join against another table in the database. Overrides SelectInterface::innerJoin
SelectExtender::isNotNull function Sets a condition that the specified field be NOT NULL. Overrides ConditionInterface::isNotNull
SelectExtender::isNull function Sets a condition that the specified field be NULL. Overrides ConditionInterface::isNull
SelectExtender::isPrepared public function Indicates if preExecute() has already been called on that object. Overrides SelectInterface::isPrepared
SelectExtender::join public function Default Join against another table in the database. Overrides SelectInterface::join
SelectExtender::leftJoin public function Left Outer Join against another table in the database. Overrides SelectInterface::leftJoin
SelectExtender::nextPlaceholder public function Implements Drupal\Core\Database\Query\PlaceholderInterface::nextPlaceholder(). Overrides PlaceholderInterface::nextPlaceholder
SelectExtender::notExists public function Sets a condition that the specified subquery returns no values. Overrides ConditionInterface::notExists
SelectExtender::orderBy public function Orders the result set by a given field. Overrides SelectInterface::orderBy
SelectExtender::orderRandom public function Orders the result set by a random value. Overrides SelectInterface::orderRandom
SelectExtender::preExecute public function Generic preparation and validation for a SELECT query. Overrides SelectInterface::preExecute
SelectExtender::range public function Restricts a query to a given range in the result set. Overrides SelectInterface::range
SelectExtender::rightJoin public function Right Outer Join against another table in the database. Overrides SelectInterface::rightJoin
SelectExtender::union public function Add another Select query to UNION to this one. Overrides SelectInterface::union
SelectExtender::uniqueIdentifier public function Implements Drupal\Core\Database\Query\PlaceholderInterface::uniqueIdentifier(). Overrides PlaceholderInterface::uniqueIdentifier
SelectExtender::where public function Adds an arbitrary WHERE clause to the query. Overrides ConditionInterface::where
SelectExtender::__call public function Magic override for undefined methods.
SelectExtender::__clone public function Clone magic method. Overrides SelectInterface::__clone
SelectExtender::__construct public function 2
SelectExtender::__toString public function