The same problem occurs when using a negativ argument filter i.e. checking "exclude argument". If there are null values in the column the null rows are regarded as having(!) the excluded value. This is commonly not desired.

The SQL Code is
... WHERE field != 'x' ...

and should be
... WHERE field != 'x' OR field IS NULL

Sorry, but I am not responsible for his ugly SQL behaviour.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skylord’s picture

subscribing
For excluding argument i use a simple patch to handlers/views_handler_argument_numeric.inc:

--- handlers/views_handler_argument_numeric.inc.orig    2010-04-22 12:03:06.000000000 +0400
+++ handlers/views_handler_argument_numeric.inc 2010-04-22 12:10:27.000000000 +0400
@@ -84,11 +84,11 @@
     if (count($this->value) > 1) {
       $operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
       $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
-      $this->query->add_where(0, "$this->table_alias.$this->real_field $operator ($placeholders)", $this->value);
+      $this->query->add_where(0, "$this->table_alias.$this->real_field $operator ($placeholders)" . (empty($this->options['not']) ? '' : " OR $this->table_alias.$this->real_field IS NULL"), $this->value);
     }
     else {
       $operator = empty($this->options['not']) ? '=' : '!=';
-      $this->query->add_where(0, "$this->table_alias.$this->real_field $operator %d", $this->argument);
+      $this->query->add_where(0, "$this->table_alias.$this->real_field $operator %d" . (empty($this->options['not']) ? '' : " OR $this->table_alias.$this->real_field IS NULL"), $this->argument);
     }
   }
 }

aw04obee’s picture

Big thank you - just ran into this problem. This certainly should be committed.

dawehner’s picture

Status: Active » Needs work

Update to make it as a real patch

voxpelli’s picture

Assigned: Unassigned » dawehner
Status: Needs work » Needs review
FileSize
1.19 KB

Here's a patch for Views 6.x-2.x and Views 6.x-3.x (same patch works for both).

Seems like the 7.x-3.x isn't in a state to accept this patch.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Views 7.x-3.x will need a slightly different patch.

Looks fine.

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to D6 2.x and 3.x

dawehner’s picture

Status: Patch (to be ported) » Needs work
FileSize
2.6 KB

Uploading the progress

dawehner’s picture

Status: Needs work » Needs review
FileSize
1.5 KB

So here is a real patch.

dawehner’s picture

Status: Needs review » Fixed

Commited to git.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.