Skip to content

Commit

Permalink
Issue #813540 by jbrown, chx: Fixed Comparisons involving NULL must n…
Browse files Browse the repository at this point in the history
…ever return true.
  • Loading branch information
webchick committed Dec 11, 2011
1 parent e59e9d9 commit 06f3108
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 1 addition & 4 deletions includes/database/query.inc
Expand Up @@ -1704,9 +1704,6 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
if (is_array($value)) {
$operator = 'IN';
}
elseif (!isset($value)) {
$operator = 'IS NULL';
}
else {
$operator = '=';
}
Expand Down Expand Up @@ -1740,7 +1737,7 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
* Implements QueryConditionInterface::isNull().
*/
public function isNull($field) {
return $this->condition($field);
return $this->condition($field, NULL, 'IS NULL');
}

/**
Expand Down
18 changes: 16 additions & 2 deletions modules/simpletest/tests/database_test.test
Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 06f3108

Please sign in to comment.