From: Laurent Dami Date: Mon, 23 Mar 2009 21:07:23 +0000 (+0000) Subject: fixed the failing tests X-Git-Tag: v1.70~198 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f2d5020d799a39cecb1f165a75b15b793a0d3453;p=dbsrgits%2FSQL-Abstract.git fixed the failing tests --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 8e46156..c0de4d5 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -452,15 +452,11 @@ sub _where_op_in_hash { $self->_SWITCH_refkind($v, { ARRAYREF => sub { - # LDNOTE : should deprecate {-or => [...]} and {-and => [...]} - # because they are misleading; the only proper way would be - # -nest => [-or => ...], -nest => [-and ...] return $self->_where_ARRAYREF($v, $op eq 'NEST' ? '' : $op); }, HASHREF => sub { if ($op eq 'OR') { - belch "-or => {...} should be -nest => [...]"; return $self->_where_ARRAYREF([%$v], 'OR'); } else { # NEST | AND @@ -594,18 +590,17 @@ sub _where_field_op_ARRAYREF { if(@$vals) { $self->_debug("ARRAY($vals) means multiple elements: [ @$vals ]"); - - - # LDNOTE : change the distribution logic when + # LDNOTE : had planned to change the distribution logic when # $op =~ $self->{inequality_op}, because of Morgan laws : # with {field => {'!=' => [22, 33]}}, it would be ridiculous to generate # WHERE field != 22 OR field != 33 : the user probably means # WHERE field != 22 AND field != 33. - my $logic = ($op =~ $self->{inequality_op}) ? 'AND' : 'OR'; + # To do this, replace the line below by : + # my $logic = ($op =~ $self->{inequality_op}) ? 'AND' : 'OR'; + # return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic); # distribute $op over each member of @$vals - return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic); - + return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals]); } else { # try to DWIM on equality operators @@ -1648,19 +1643,9 @@ Which would generate: To test against multiple values, just enclose the values in an arrayref: - status => { '!=', ['assigned', 'in-progress', 'pending'] }; - -Which would give you: - - "WHERE status != ? AND status != ? AND status != ?" - -Notice that since the operator was recognized as being a 'negative' -operator, the arrayref was interpreted with 'AND' logic (because -of Morgan's laws). By contrast, the reverse - status => { '=', ['assigned', 'in-progress', 'pending'] }; -would generate : +Which would give you: "WHERE status = ? OR status = ? OR status = ?" diff --git a/t/02where.t b/t/02where.t index 0c28faf..1bdb8cb 100755 --- a/t/02where.t +++ b/t/02where.t @@ -156,6 +156,7 @@ my @handle_tests = ( }, { +# LDNOTE 23.03.09 : modified test below, just parentheses differ where => { foo => {-not_like => [7,8,9]}, fum => {'like' => [qw/a b/]}, nix => {'between' => [100,200] }, @@ -163,7 +164,7 @@ my @handle_tests = ( wix => {'in' => [qw/zz yy/]}, wux => {'not_in' => [qw/30 40/]} }, - stmt => " WHERE ( ( ( foo NOT LIKE ? ) OR ( foo NOT LIKE ? ) OR ( foo NOT LIKE ? ) ) AND ( ( fum LIKE ? ) OR ( fum LIKE ? ) ) AND nix BETWEEN ? AND ? AND nox NOT BETWEEN ? AND ? AND wix IN ( ?, ? ) AND wux NOT IN ( ?, ? ) )", + stmt => " WHERE ( ( ( foo NOT LIKE ? ) OR ( foo NOT LIKE ? ) OR ( foo NOT LIKE ? ) ) AND ( ( fum LIKE ? ) OR ( fum LIKE ? ) ) AND ( nix BETWEEN ? AND ? ) AND ( nox NOT BETWEEN ? AND ? ) AND wix IN ( ?, ? ) AND wux NOT IN ( ?, ? ) )", bind => [7,8,9,'a','b',100,200,150,160,'zz','yy','30','40'], },