includes/database/query.inc | 5 +---- modules/simpletest/tests/database_test.test | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/includes/database/query.inc b/includes/database/query.inc index 23b652f..4bc2f40 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -1637,9 +1637,6 @@ class DatabaseCondition implements QueryConditionInterface, Countable { if (is_array($value)) { $operator = 'IN'; } - elseif (!isset($value)) { - $operator = 'IS NULL'; - } else { $operator = '='; } @@ -1673,7 +1670,7 @@ class DatabaseCondition implements QueryConditionInterface, Countable { * Implements QueryConditionInterface::isNull(). */ public function isNull($field) { - return $this->condition($field); + return $this->condition($field, NULL, 'IS NULL'); } /** diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 143640d..bb45a9d 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -1454,13 +1454,27 @@ 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') ->execute()->fetchCol(); @@ -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')