class SelectQueryExtender

The base extender class for Select queries.

Hierarchy

Expanded class hierarchy of SelectQueryExtender

3 string references to 'SelectQueryExtender'
DatabaseTaggingTestCase::testExtenderHasAllTags in modules/simpletest/tests/database_test.test
Test extended query tagging "has all of these tags" functionality.
DatabaseTaggingTestCase::testExtenderHasAnyTag in modules/simpletest/tests/database_test.test
Test extended query tagging "has at least one of these tags" functionality.
DatabaseTaggingTestCase::testExtenderHasTag in modules/simpletest/tests/database_test.test
Confirm that an extended query has a "tag" added to it.

File

includes/database/select.inc, line 536

View source
class SelectQueryExtender implements SelectQueryInterface {
  
  /**
   * The SelectQuery object we are extending/decorating.
   *
   * @var SelectQueryInterface
   */
  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(SelectQueryInterface $query, DatabaseConnection $connection) {
    $this->uniqueIdentifier = uniqid('', TRUE);
    $this->query = $query;
    $this->connection = $connection;
  }
  
  /**
   * Implements QueryPlaceholderInterface::uniqueIdentifier().
   */
  public function uniqueIdentifier() {
    return $this->uniqueIdentifier;
  }
  
  /**
   * Implements QueryPlaceholderInterface::nextPlaceholder().
   */
  public function nextPlaceholder() {
    return $this->placeholder++;
  }
  /* Implementations of QueryAlterableInterface. */
  public function addTag($tag) {
    $this->query
      ->addTag($tag);
    return $this;
  }
  public function hasTag($tag) {
    return $this->query
      ->hasTag($tag);
  }
  public function hasAllTags() {
    $args = func_get_args();
    return call_user_func_array(array(
      $this->query,
      'hasAllTags',
    ), $args);
  }
  public function hasAnyTag() {
    $args = func_get_args();
    return call_user_func_array(array(
      $this->query,
      'hasAnyTag',
    ), $args);
  }
  public function addMetaData($key, $object) {
    $this->query
      ->addMetaData($key, $object);
    return $this;
  }
  public function getMetaData($key) {
    return $this->query
      ->getMetaData($key);
  }
  /* Implementations of QueryConditionInterface 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(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder) {
    return $this->query
      ->compile($connection, $queryPlaceholder);
  }
  public function compiled() {
    return $this->query
      ->compiled();
  }
  /* Implementations of QueryConditionInterface 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(DatabaseConnection $connection) {
    return $this->query
      ->havingCompile($connection);
  }
  /* Implementations of QueryExtendableInterface. */
  public function extend($extender_name) {
    // The extender can be anywhere so this needs to go to the registry, which
    // is surely loaded by now.
    $class = $this->connection
      ->getDriverClass($extender_name, array(), TRUE);
    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(QueryPlaceholderInterface $queryPlaceholder = NULL) {
    return $this->query
      ->getArguments($queryPlaceholder);
  }
  public function isPrepared() {
    return $this->query
      ->isPrepared();
  }
  public function preExecute(SelectQueryInterface $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(SelectQueryInterface $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(SelectQueryInterface $select) {
    $this->query
      ->exists($select);
    return $this;
  }
  public function notExists(SelectQueryInterface $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 SelectQueryInterface) {
      return $this;
    }
    else {
      return $return;
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
SelectQueryExtender::$connection protected property The connection object on which to run this query.
SelectQueryExtender::$placeholder protected property The placeholder counter.
SelectQueryExtender::$query protected property The SelectQuery object we are extending/decorating.
SelectQueryExtender::$uniqueIdentifier protected property A unique identifier for this query object.
SelectQueryExtender::addExpression public function Overrides SelectQueryInterface::addExpression
SelectQueryExtender::addField public function Overrides SelectQueryInterface::addField
SelectQueryExtender::addJoin public function Overrides SelectQueryInterface::addJoin
SelectQueryExtender::addMetaData public function Overrides QueryAlterableInterface::addMetaData
SelectQueryExtender::addTag public function Overrides QueryAlterableInterface::addTag
SelectQueryExtender::arguments public function Overrides QueryConditionInterface::arguments
SelectQueryExtender::compile public function Overrides QueryConditionInterface::compile
SelectQueryExtender::compiled public function Overrides QueryConditionInterface::compiled
SelectQueryExtender::condition public function Overrides QueryConditionInterface::condition
SelectQueryExtender::conditions public function Overrides QueryConditionInterface::conditions
SelectQueryExtender::countQuery public function Overrides SelectQueryInterface::countQuery 1
SelectQueryExtender::distinct public function Overrides SelectQueryInterface::distinct
SelectQueryExtender::execute public function 2
SelectQueryExtender::exists public function Overrides QueryConditionInterface::exists
SelectQueryExtender::extend public function Overrides QueryExtendableInterface::extend
SelectQueryExtender::fields public function Overrides SelectQueryInterface::fields
SelectQueryExtender::forUpdate public function Overrides SelectQueryInterface::forUpdate
SelectQueryExtender::getArguments public function Overrides SelectQueryInterface::getArguments
SelectQueryExtender::getExpressions public function Overrides SelectQueryInterface::getExpressions
SelectQueryExtender::getFields public function Overrides SelectQueryInterface::getFields
SelectQueryExtender::getGroupBy public function Overrides SelectQueryInterface::getGroupBy
SelectQueryExtender::getMetaData public function Overrides QueryAlterableInterface::getMetaData
SelectQueryExtender::getOrderBy public function Overrides SelectQueryInterface::getOrderBy
SelectQueryExtender::getTables public function Overrides SelectQueryInterface::getTables
SelectQueryExtender::getUnion public function Overrides SelectQueryInterface::getUnion
SelectQueryExtender::groupBy public function Overrides SelectQueryInterface::groupBy
SelectQueryExtender::hasAllTags public function Overrides QueryAlterableInterface::hasAllTags
SelectQueryExtender::hasAnyTag public function Overrides QueryAlterableInterface::hasAnyTag
SelectQueryExtender::hasTag public function Overrides QueryAlterableInterface::hasTag
SelectQueryExtender::having public function
SelectQueryExtender::havingArguments public function
SelectQueryExtender::havingCompile public function
SelectQueryExtender::havingCondition public function Overrides SelectQueryInterface::havingCondition
SelectQueryExtender::havingConditions public function
SelectQueryExtender::innerJoin public function Overrides SelectQueryInterface::innerJoin
SelectQueryExtender::isNotNull function Overrides QueryConditionInterface::isNotNull
SelectQueryExtender::isNull function Overrides QueryConditionInterface::isNull
SelectQueryExtender::isPrepared public function Overrides SelectQueryInterface::isPrepared
SelectQueryExtender::join public function Overrides SelectQueryInterface::join
SelectQueryExtender::leftJoin public function Overrides SelectQueryInterface::leftJoin
SelectQueryExtender::nextPlaceholder public function Implements QueryPlaceholderInterface::nextPlaceholder(). Overrides QueryPlaceholderInterface::nextPlaceholder
SelectQueryExtender::notExists public function Overrides QueryConditionInterface::notExists
SelectQueryExtender::orderBy public function Overrides SelectQueryInterface::orderBy
SelectQueryExtender::orderRandom public function Overrides SelectQueryInterface::orderRandom
SelectQueryExtender::preExecute public function Overrides SelectQueryInterface::preExecute
SelectQueryExtender::range public function Overrides SelectQueryInterface::range
SelectQueryExtender::rightJoin public function Overrides SelectQueryInterface::rightJoin
SelectQueryExtender::union public function Overrides SelectQueryInterface::union
SelectQueryExtender::uniqueIdentifier public function Implements QueryPlaceholderInterface::uniqueIdentifier(). Overrides QueryPlaceholderInterface::uniqueIdentifier
SelectQueryExtender::where public function Overrides QueryConditionInterface::where
SelectQueryExtender::__call public function Magic override for undefined methods.
SelectQueryExtender::__clone public function Overrides SelectQueryInterface::__clone
SelectQueryExtender::__construct public function 2
SelectQueryExtender::__toString public function

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