From 934a063e99c42f67621becc632a71a3f5102b303 Mon Sep 17 00:00:00 2001 From: miker Date: Sat, 12 Jun 2010 04:49:58 +0000 Subject: [PATCH] correct nullability test for certain WHERE clauses git-svn-id: svn://svn.open-ils.org/ILS/trunk@16694 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Reporter/SQLBuilder.pm | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm b/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm index a231899d0..637cbc50d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm +++ b/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm @@ -946,18 +946,38 @@ sub toSQL { } elsif (lc($op) eq '= any') { $val = $$val[0] if (ref($val) eq 'ARRAY'); $val = $val->toSQL; - $sql = "$val = ANY (".$self->SUPER::toSQL.")"; + if ($rel && $rel->is_nullable) { # need to redo this + $sql = "((". $self->SUPER::toSQL .") IS NULL OR "; + } else { + $sql = ''; + } + $sql .= "$val = ANY (".$self->SUPER::toSQL.")"; } elsif (lc($op) eq '<> any') { $val = $$val[0] if (ref($val) eq 'ARRAY'); $val = $val->toSQL; - $sql = "$val <> ANY (".$self->SUPER::toSQL.")"; + if ($rel && $rel->is_nullable) { # need to redo this + $sql = "((". $self->SUPER::toSQL .") IS NULL OR "; + } else { + $sql = ''; + } + $sql .= "$val <> ANY (".$self->SUPER::toSQL.")"; } elsif (lc($op) eq 'is blank') { - $sql = '('. $self->SUPER::toSQL ." IS NULL OR ". $self->SUPER::toSQL ." = '')"; + if ($rel && $rel->is_nullable) { # need to redo this + $sql = "((". $self->SUPER::toSQL .") IS NULL OR "; + } else { + $sql = ''; + } + $sql .= '('. $self->SUPER::toSQL ." IS NULL OR ". $self->SUPER::toSQL ." = '')"; } elsif (lc($op) eq 'is not blank') { - $sql = '('. $self->SUPER::toSQL ." IS NOT NULL AND ". $self->SUPER::toSQL ." <> '')"; + if ($rel && $rel->is_nullable) { # need to redo this + $sql = "((". $self->SUPER::toSQL .") IS NULL OR "; + } else { + $sql = ''; + } + $sql .= '('. $self->SUPER::toSQL ." IS NOT NULL AND ". $self->SUPER::toSQL ." <> '')"; } elsif (lc($op) eq 'between') { $sql .= " BETWEEN ". join(" AND ", map { $_->toSQL } @$val); -- 2.11.0