Commit 4e8234c5 authored by Dries's avatar Dries
Browse files

- Patch #813540 by jbrown, chx: comparisons involving NULL must never return true.

parent 2a378fe5
......@@ -1704,9 +1704,6 @@ public function condition($field, $value = NULL, $operator = NULL) {
if (is_array($value)) {
$operator = 'IN';
}
elseif (!isset($value)) {
$operator = 'IS NULL';
}
else {
$operator = '=';
}
......@@ -1740,7 +1737,7 @@ public function where($snippet, $args = array()) {
* Implements QueryConditionInterface::isNull().
*/
public function isNull($field) {
return $this->condition($field);
return $this->condition($field, NULL, 'IS NULL');
}
/**
......
......@@ -1454,11 +1454,25 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
}
/**
* Test that we can find a record with a NULL value.
* Test that a comparison with NULL is always FALSE.
*/
function testNullCondition() {
$this->ensureSampleDataNull();
$names = db_select('test_null', 'tn')
->fields('tn', array('name'))
->condition('age', NULL)
->execute()->fetchCol();
$this->assertEqual(count($names), 0, t('No records found when comparing to NULL.'));
}
/**
* Test that we can find a record with a NULL value.
*/
function testIsNullCondition() {
$this->ensureSampleDataNull();
$names = db_select('test_null', 'tn')
->fields('tn', array('name'))
->isNull('age')
......@@ -1471,7 +1485,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
/**
* Test that we can find a record without a NULL value.
*/
function testNotNullCondition() {
function testIsNotNullCondition() {
$this->ensureSampleDataNull();
$names = db_select('test_null', 'tn')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment