From: Peter Rabbitson Date: Tue, 28 Apr 2009 21:57:54 +0000 (+0000) Subject: A much better fix for the x => [ -and, ... ] corner case X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4030915f8210352b34a10d0780557b26aac7c6a6;p=scpubgit%2FQ-Branch.git A much better fix for the x => [ -and, ... ] corner case --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 24a1c87..09d64e6 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -606,17 +606,25 @@ sub _where_field_op_ARRAYREF { if(@$vals) { $self->_debug("ARRAY($vals) means multiple elements: [ @$vals ]"); + # see if the first element is an -and/-or op + my $logic; + if ($vals->[0] =~ /^ - ( AND|OR ) $/ix) { + $logic = uc $1; + shift @$vals; + } + + # distribute $op over each remaining member of @$vals, append logic if exists + return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic); + # 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. - # To do this, replace the line below by : + # To do this, replace the above to roughly : # 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]); } else { # try to DWIM on equality operators