diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-12-31 20:43:43 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-12-31 20:43:43 +0000 |
commit | 98f287b55a88d06199cda88b6929af589c182e23 (patch) | |
tree | 50b7a7a71eb8c54e417cbaa8f4d6f1a975e9d72f /includes/database/query.inc | |
parent | 0c8931dd76d066c5332846d478964d1145c5c6c2 (diff) | |
download | brdo-98f287b55a88d06199cda88b6929af589c182e23.tar.gz brdo-98f287b55a88d06199cda88b6929af589c182e23.tar.bz2 |
#1001242 by agentrickard, pwolanin, Crell, chx: Add DBTNG support for EXISTS conditions.
Diffstat (limited to 'includes/database/query.inc')
-rw-r--r-- | includes/database/query.inc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/includes/database/query.inc b/includes/database/query.inc index 7c590c220..de421b30c 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -77,6 +77,28 @@ interface QueryConditionInterface { public function isNotNull($field); /** + * Sets a condition that the specified subquery returns values. + * + * @param SelectQueryInterface $select + * The subquery that must contain results. + * + * @return QueryConditionInterface + * The called object. + */ + public function exists(SelectQueryInterface $select); + + /** + * Sets a condition that the specified subquery returns no values. + * + * @param SelectQueryInterface $select + * The subquery that must not contain results. + * + * @return QueryConditionInterface + * The called object. + */ + public function notExists(SelectQueryInterface $select); + + /** * Gets a complete list of all conditions in this conditional clause. * * This method returns by reference. That allows alter hooks to access the @@ -727,6 +749,22 @@ class DeleteQuery extends Query implements QueryConditionInterface { } /** + * Implements QueryConditionInterface::exists(). + */ + public function exists(SelectQueryInterface $select) { + $this->condition->exists($select); + return $this; + } + + /** + * Implements QueryConditionInterface::notExists(). + */ + public function notExists(SelectQueryInterface $select) { + $this->condition->notExists($select); + return $this; + } + + /** * Implements QueryConditionInterface::conditions(). */ public function &conditions() { @@ -947,6 +985,22 @@ class UpdateQuery extends Query implements QueryConditionInterface { } /** + * Implements QueryConditionInterface::exists(). + */ + public function exists(SelectQueryInterface $select) { + $this->condition->exists($select); + return $this; + } + + /** + * Implements QueryConditionInterface::notExists(). + */ + public function notExists(SelectQueryInterface $select) { + $this->condition->notExists($select); + return $this; + } + + /** * Implements QueryConditionInterface::conditions(). */ public function &conditions() { @@ -1417,6 +1471,22 @@ class MergeQuery extends Query implements QueryConditionInterface { } /** + * Implements QueryConditionInterface::exists(). + */ + public function exists(SelectQueryInterface $select) { + $this->condition->exists($select); + return $this; + } + + /** + * Implements QueryConditionInterface::notExists(). + */ + public function notExists(SelectQueryInterface $select) { + $this->condition->notExists($select); + return $this; + } + + /** * Implements QueryConditionInterface::conditions(). */ public function &conditions() { @@ -1615,6 +1685,20 @@ class DatabaseCondition implements QueryConditionInterface, Countable { } /** + * Implements QueryConditionInterface::exists(). + */ + public function exists(SelectQueryInterface $select) { + return $this->condition('', $select, 'EXISTS'); + } + + /** + * Implements QueryConditionInterface::notExists(). + */ + public function notExists(SelectQueryInterface $select) { + return $this->condition('', $select, 'NOT EXISTS'); + } + + /** * Implements QueryConditionInterface::conditions(). */ public function &conditions() { @@ -1756,6 +1840,8 @@ class DatabaseCondition implements QueryConditionInterface, Countable { 'BETWEEN' => array('delimiter' => ' AND '), 'IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'), 'NOT IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'), + 'EXISTS' => array('prefix' => ' (', 'postfix' => ')'), + 'NOT EXISTS' => array('prefix' => ' (', 'postfix' => ')'), 'IS NULL' => array('use_value' => FALSE), 'IS NOT NULL' => array('use_value' => FALSE), // Use backslash for escaping wildcard characters. |