summaryrefslogtreecommitdiff
path: root/includes/database/query.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/database/query.inc')
-rw-r--r--includes/database/query.inc61
1 files changed, 57 insertions, 4 deletions
diff --git a/includes/database/query.inc b/includes/database/query.inc
index dd6a4da9a..d22c0751a 100644
--- a/includes/database/query.inc
+++ b/includes/database/query.inc
@@ -48,6 +48,26 @@ interface QueryConditionInterface {
public function where($snippet, $args = array());
/**
+ * Set a condition that the specified field be NULL.
+ *
+ * @param $field
+ * The name of the field to check.
+ * @return
+ * The called object.
+ */
+ public function isNull($field);
+
+ /**
+ * Set a condition that the specified field be NOT NULL.
+ *
+ * @param $field
+ * The name of the field to check.
+ * @return
+ * The called object.
+ */
+ public function isNotNull($field);
+
+ /**
* Gets a complete list of all conditions in this conditional clause.
*
* This method returns by reference. That allows alter hooks to access the
@@ -749,6 +769,16 @@ class DeleteQuery extends Query implements QueryConditionInterface {
return $this;
}
+ public function isNull($field) {
+ $this->condition->isNull($field);
+ return $this;
+ }
+
+ public function isNotNull($field) {
+ $this->condition->isNotNull($field);
+ return $this;
+ }
+
public function &conditions() {
return $this->condition->conditions();
}
@@ -852,6 +882,16 @@ class UpdateQuery extends Query implements QueryConditionInterface {
return $this;
}
+ public function isNull($field) {
+ $this->condition->isNull($field);
+ return $this;
+ }
+
+ public function isNotNull($field) {
+ $this->condition->isNotNull($field);
+ return $this;
+ }
+
public function &conditions() {
return $this->condition->conditions();
}
@@ -1012,6 +1052,14 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
return $this;
}
+ public function isNull($field) {
+ return $this->condition($field, NULL, 'IS NULL');
+ }
+
+ public function isNotNull($field) {
+ return $this->condition($field, NULL, 'IS NOT NULL');
+ }
+
public function &conditions() {
return $this->conditions;
}
@@ -1061,6 +1109,7 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
'postfix' => '',
'delimiter' => '',
'operator' => $condition['operator'],
+ 'use_value' => TRUE,
);
$operator = $connection->mapConditionOperator($condition['operator']);
if (!isset($operator)) {
@@ -1079,10 +1128,12 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
$condition['value'] = array($condition['value']);
}
$placeholders = array();
- foreach ($condition['value'] as $value) {
- $placeholder = ':db_condition_placeholder_' . $next_placeholder++;
- $arguments[$placeholder] = $value;
- $placeholders[] = $placeholder;
+ if ($operator['use_value']) {
+ foreach ($condition['value'] as $value) {
+ $placeholder = ':db_condition_placeholder_' . $next_placeholder++;
+ $arguments[$placeholder] = $value;
+ $placeholders[] = $placeholder;
+ }
}
$condition_fragments[] = ' (' . $condition['field'] . ' ' . $operator['operator'] . ' ' . $operator['prefix'] . implode($operator['delimiter'], $placeholders) . $operator['postfix'] . ') ';
@@ -1122,6 +1173,8 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
'IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'),
'NOT IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'),
'LIKE' => array('operator' => 'LIKE'),
+ 'IS NULL' => array('use_value' => FALSE),
+ 'IS NOT NULL' => array('use_value' => FALSE),
);
$return = isset($specials[$operator]) ? $specials[$operator] : array();