diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php index 2d3159c..251fb59 100644 --- a/core/lib/Drupal/Core/Database/Query/Select.php +++ b/core/lib/Drupal/Core/Database/Query/Select.php @@ -121,6 +121,20 @@ class Select extends Query implements SelectInterface { */ protected $forUpdate = FALSE; + /** + * Constructor + * + * Creates a new select query. + * + * @param string $table + * The base table for the select query + * @param string $alias + * The alias for the table + * @param Drupal\Core\Database\Connection $connection + * Database connection through which the table will be accessed + * @param array $options + * Query options + */ public function __construct($table, $alias = NULL, Connection $connection, $options = array()) { $options['return'] = Database::RETURN_STATEMENT; parent::__construct($connection, $options); @@ -129,45 +143,68 @@ class Select extends Query implements SelectInterface { $this->addJoin(NULL, $table, $alias); } - /* Implementations of Drupal\Core\Database\Query\AlterableInterface. */ - + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::addTag(). + */ public function addTag($tag) { $this->alterTags[$tag] = 1; return $this; } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::hasTag(). + */ public function hasTag($tag) { return isset($this->alterTags[$tag]); } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::hasAllTags(). + */ public function hasAllTags() { return !(boolean)array_diff(func_get_args(), array_keys($this->alterTags)); } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::hasAnyTag(). + */ public function hasAnyTag() { return (boolean)array_intersect(func_get_args(), array_keys($this->alterTags)); } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::addMetaData(). + */ public function addMetaData($key, $object) { $this->alterMetaData[$key] = $object; return $this; } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::getMetaData(). + */ public function getMetaData($key) { return isset($this->alterMetaData[$key]) ? $this->alterMetaData[$key] : NULL; } - /* Implementations of Drupal\Core\Database\Query\ConditionInterface for the WHERE clause. */ - + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::condition(). + */ public function condition($field, $value = NULL, $operator = NULL) { $this->where->condition($field, $value, $operator); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::conditions(). + */ public function &conditions() { return $this->where->conditions(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::arguments(). + */ public function arguments() { if (!$this->compiled()) { return NULL; @@ -200,31 +237,49 @@ class Select extends Query implements SelectInterface { return $args; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::where(). + */ public function where($snippet, $args = array()) { $this->where->where($snippet, $args); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::isNull(). + */ public function isNull($field) { $this->where->isNull($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::isNull(). + */ public function isNotNull($field) { $this->where->isNotNull($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::exists(). + */ public function exists(SelectInterface $select) { $this->where->exists($select); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::notExists(). + */ public function notExists(SelectInterface $select) { $this->where->notExists($select); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::compile(). + */ public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) { $this->where->compile($connection, $queryPlaceholder); $this->having->compile($connection, $queryPlaceholder); @@ -242,6 +297,9 @@ class Select extends Query implements SelectInterface { } } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::compiled(). + */ public function compiled() { if (!$this->where->compiled() || !$this->having->compiled()) { return FALSE; @@ -265,32 +323,51 @@ class Select extends Query implements SelectInterface { return TRUE; } - /* Implementations of Drupal\Core\Database\Query\ConditionInterface for the HAVING clause. */ - + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::condition() for + * the HAVING clause. + */ public function havingCondition($field, $value = NULL, $operator = NULL) { $this->having->condition($field, $value, $operator); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::conditions() for + * the HAVING clause. + */ public function &havingConditions() { return $this->having->conditions(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::arguments() for + * the HAVING clause. + */ public function havingArguments() { return $this->having->arguments(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::where() for the + * HAVING clause. + */ public function having($snippet, $args = array()) { $this->having->where($snippet, $args); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::compile() for the + * HAVING clause. + */ public function havingCompile(Connection $connection) { return $this->having->compile($connection, $this); } - /* Implementations of Drupal\Core\Database\Query\ExtendableInterface. */ - + /** + * Implements Drupal\Core\Database\Query\ExtendableInterface::extend(). + */ public function extend($extender_name) { $override_class = $extender_name . '_' . $this->connection->driver(); if (class_exists($override_class)) { @@ -299,26 +376,45 @@ class Select extends Query implements SelectInterface { return new $extender_name($this, $this->connection); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::isNull() for the + * HAVING clause. + */ public function havingIsNull($field) { $this->having->isNull($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull() for + * the HAVING clause. + */ public function havingIsNotNull($field) { $this->having->isNotNull($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::exists() for the + * HAVING clause. + */ public function havingExists(SelectInterface $select) { $this->having->exists($select); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::notExists() for + * the HAVING clause. + */ public function havingNotExists(SelectInterface $select) { $this->having->notExists($select); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::forUpdate(). + */ public function forUpdate($set = TRUE) { if (isset($set)) { $this->forUpdate = $set; @@ -326,32 +422,51 @@ class Select extends Query implements SelectInterface { return $this; } - /* Alter accessors to expose the query data to alter hooks. */ - + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getFields(). + */ public function &getFields() { return $this->fields; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getExpressions(). + */ public function &getExpressions() { return $this->expressions; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getOrderBy(). + */ public function &getOrderBy() { return $this->order; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getGroupBy(). + */ public function &getGroupBy() { return $this->group; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getTables(). + */ public function &getTables() { return $this->tables; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getUnion(). + */ public function &getUnion() { return $this->union; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getArguments(). + */ public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) { if (!isset($queryPlaceholder)) { $queryPlaceholder = $this; @@ -361,17 +476,14 @@ class Select extends Query implements SelectInterface { } /** - * Indicates if preExecute() has already been called on that object. + * Implements Drupal\Core\Database\Query\SelectInterface::isPrepared(). */ public function isPrepared() { return $this->prepared; } /** - * Generic preparation and validation for a SELECT query. - * - * @return - * TRUE if the validation was successful, FALSE if not. + * Implements Drupal\Core\Database\Query\SelectInterface::preExecute(). */ public function preExecute(SelectInterface $query = NULL) { // If no query object is passed in, use $this. @@ -409,6 +521,9 @@ class Select extends Query implements SelectInterface { return $this->prepared; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::execute(). + */ public function execute() { // If validation fails, simply return NULL. // Note that validation routines in preExecute() may throw exceptions instead. @@ -420,11 +535,17 @@ class Select extends Query implements SelectInterface { return $this->connection->query((string) $this, $args, $this->queryOptions); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::distinct(). + */ public function distinct($distinct = TRUE) { $this->distinct = $distinct; return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::addField(). + */ public function addField($table_alias, $field, $alias = NULL) { // If no alias is specified, first try the field name itself. if (empty($alias)) { @@ -453,6 +574,9 @@ class Select extends Query implements SelectInterface { return $alias; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::fields(). + */ public function fields($table_alias, array $fields = array()) { if ($fields) { @@ -469,6 +593,9 @@ class Select extends Query implements SelectInterface { return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::addExpression(). + */ public function addExpression($expression, $alias = NULL, $arguments = array()) { if (empty($alias)) { $alias = 'expression'; @@ -490,22 +617,37 @@ class Select extends Query implements SelectInterface { return $alias; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::join(). + */ public function join($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->addJoin('INNER', $table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::join(). + */ public function innerJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->addJoin('INNER', $table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::leftJoin(). + */ public function leftJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->addJoin('LEFT OUTER', $table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::rightJoin(). + */ public function rightJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->addJoin('RIGHT OUTER', $table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::addJoin(). + */ public function addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = array()) { if (empty($alias)) { @@ -539,22 +681,34 @@ class Select extends Query implements SelectInterface { return $alias; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::orderBy(). + */ public function orderBy($field, $direction = 'ASC') { $this->order[$field] = $direction; return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::orderRandom(). + */ public function orderRandom() { $alias = $this->addExpression('RAND()', 'random_field'); $this->orderBy($alias); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::range(). + */ public function range($start = NULL, $length = NULL) { $this->range = func_num_args() ? array('start' => $start, 'length' => $length) : array(); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::union(). + */ public function union(SelectInterface $query, $type = '') { // Handle UNION aliasing. switch ($type) { @@ -577,11 +731,17 @@ class Select extends Query implements SelectInterface { return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::groupBy(). + */ public function groupBy($field) { $this->group[$field] = $field; return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::countQuery(). + */ public function countQuery() { // Create our new query object that we will mutate into a count query. $count = clone($this); @@ -636,6 +796,12 @@ class Select extends Query implements SelectInterface { return $query; } + /** + * Return the query as a string. + * + * @return string + * The compiled query + */ public function __toString() { // For convenience, we compile the query ourselves if the caller forgot // to do it. This allows constructs like "(string) $query" to work. When @@ -751,6 +917,11 @@ class Select extends Query implements SelectInterface { return $query; } + /** + * Clone the Select query object. + * + * Clones the query being sure to clone all object properties as well. + */ public function __clone() { // On cloning, also clone the dependent objects. However, we do not // want to clone the database connection object as that would duplicate the diff --git a/core/lib/Drupal/Core/Database/Query/SelectExtender.php b/core/lib/Drupal/Core/Database/Query/SelectExtender.php index 2f27d1b..71fc5d3 100644 --- a/core/lib/Drupal/Core/Database/Query/SelectExtender.php +++ b/core/lib/Drupal/Core/Database/Query/SelectExtender.php @@ -58,127 +58,203 @@ class SelectExtender implements SelectInterface { return $this->placeholder++; } - /* Implementations of Drupal\Core\Database\Query\AlterableInterface. */ - + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::addTag(). + */ public function addTag($tag) { $this->query->addTag($tag); return $this; } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::hasTag(). + */ public function hasTag($tag) { return $this->query->hasTag($tag); } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::hasAllTags(). + */ public function hasAllTags() { return call_user_func_array(array($this->query, 'hasAllTags'), func_get_args()); } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::hasAnyTag(). + */ public function hasAnyTag() { return call_user_func_array(array($this->query, 'hasAnyTags'), func_get_args()); } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::addMetaData(). + */ public function addMetaData($key, $object) { $this->query->addMetaData($key, $object); return $this; } + /** + * Implements Drupal\Core\Database\Query\AlterableInterface::getMetaData(). + */ public function getMetaData($key) { return $this->query->getMetaData($key); } - /* Implementations of Drupal\Core\Database\Query\ConditionInterface for the WHERE clause. */ - + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::condition(). + */ public function condition($field, $value = NULL, $operator = NULL) { $this->query->condition($field, $value, $operator); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::conditions(). + */ public function &conditions() { return $this->query->conditions(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::arguments(). + */ public function arguments() { return $this->query->arguments(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::where(). + */ public function where($snippet, $args = array()) { $this->query->where($snippet, $args); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::compile(). + */ public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) { return $this->query->compile($connection, $queryPlaceholder); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::compiled(). + */ public function compiled() { return $this->query->compiled(); } - /* Implementations of Drupal\Core\Database\Query\ConditionInterface for the HAVING clause. */ - + /** + * Returns the Drupal\Core\Database\Query\ConditionInterface::condition() for + * the HAVING clause. + */ public function havingCondition($field, $value = NULL, $operator = '=') { $this->query->havingCondition($field, $value, $operator); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::conditions() for + * the HAVING clause. + */ public function &havingConditions() { return $this->query->havingConditions(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::arguments() for + * the HAVING clause. + */ public function havingArguments() { return $this->query->havingArguments(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::where() for + * the HAVING clause. + */ public function having($snippet, $args = array()) { $this->query->having($snippet, $args); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::compile() for + * the HAVING clause. + */ public function havingCompile(Connection $connection) { return $this->query->havingCompile($connection); } - /* Implementations of Drupal\Core\Database\Query\ExtendableInterface. */ - + /** + * Implements Drupal\Core\Database\Query\ExtendableInterface::extend(). + */ 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. */ - + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getFields(). + */ public function &getFields() { return $this->query->getFields(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getExpressions(). + */ public function &getExpressions() { return $this->query->getExpressions(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getOrderBy(). + */ public function &getOrderBy() { return $this->query->getOrderBy(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getGroupBy(). + */ public function &getGroupBy() { return $this->query->getGroupBy(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getTables(). + */ public function &getTables() { return $this->query->getTables(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getUnion(). + */ public function &getUnion() { return $this->query->getUnion(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::getArguments(). + */ public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) { return $this->query->getArguments($queryPlaceholder); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::isPrepared(). + */ public function isPrepared() { return $this->query->isPrepared(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::preExecute(). + */ public function preExecute(SelectInterface $query = NULL) { // If no query object is passed in, use $this. if (!isset($query)) { @@ -188,6 +264,9 @@ class SelectExtender implements SelectInterface { return $this->query->preExecute($query); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::execute(). + */ public function execute() { // By calling preExecute() here, we force it to preprocess the extender // object rather than just the base query object. That means @@ -199,102 +278,173 @@ class SelectExtender implements SelectInterface { return $this->query->execute(); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::distinct(). + */ public function distinct($distinct = TRUE) { $this->query->distinct($distinct); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::addField(). + */ public function addField($table_alias, $field, $alias = NULL) { return $this->query->addField($table_alias, $field, $alias); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::fields(). + */ public function fields($table_alias, array $fields = array()) { $this->query->fields($table_alias, $fields); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::addExpression(). + */ public function addExpression($expression, $alias = NULL, $arguments = array()) { return $this->query->addExpression($expression, $alias, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::join(). + */ public function join($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->query->join($table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::innerJoin(). + */ public function innerJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->query->innerJoin($table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::leftJoin(). + */ public function leftJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->query->leftJoin($table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::rightJoin(). + */ public function rightJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->query->rightJoin($table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::addJoin(). + */ public function addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->query->addJoin($type, $table, $alias, $condition, $arguments); } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::orderBy(). + */ public function orderBy($field, $direction = 'ASC') { $this->query->orderBy($field, $direction); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::orderRandom(). + */ public function orderRandom() { $this->query->orderRandom(); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::range(). + */ public function range($start = NULL, $length = NULL) { $this->query->range($start, $length); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::union(). + */ public function union(SelectInterface $query, $type = '') { $this->query->union($query, $type); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::groupBy(). + */ public function groupBy($field) { $this->query->groupBy($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::forUpdate(). + */ public function forUpdate($set = TRUE) { $this->query->forUpdate($set); return $this; } + /** + * Implements Drupal\Core\Database\Query\SelectInterface::countQuery(). + */ public function countQuery() { return $this->query->countQuery(); } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::isNull(). + */ function isNull($field) { $this->query->isNull($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull(). + */ function isNotNull($field) { $this->query->isNotNull($field); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::exists(). + */ public function exists(SelectInterface $select) { $this->query->exists($select); return $this; } + /** + * Implements Drupal\Core\Database\Query\ConditionInterface::notExists(). + */ public function notExists(SelectInterface $select) { $this->query->notExists($select); return $this; } + /** + * Return the query as a string. + * + * @return string + * The compiled query + */ public function __toString() { return (string) $this->query; } + /** + * Clone the Select query object. + * + * Clones the query being sure to clone all object properties as well. + */ public function __clone() { $this->uniqueIdentifier = uniqid('', TRUE);