Merge 'trunk' into 'and_or'
Peter Rabbitson [Tue, 28 Apr 2009 22:01:31 +0000 (22:01 +0000)]
r5918@Thesaurus (orig r5917):  arcanez | 2009-04-21 02:03:47 +0200
patch for -between to handle [\"", \""] and \["", @bind] with accompanying tests
r5922@Thesaurus (orig r5921):  ribasushi | 2009-04-21 08:30:25 +0200
Silence warning on bleadperl (by SMPETERS)
r5982@Thesaurus (orig r5981):  arcanez | 2009-04-24 20:47:06 +0200
add support for order_by => [qw/colA colB/]
r5983@Thesaurus (orig r5982):  arcanez | 2009-04-24 20:54:00 +0200
add in my changes
r5985@Thesaurus (orig r5984):  ribasushi | 2009-04-24 21:53:07 +0200
Make POD more readable, add a (failing) multikey order_by test
r5986@Thesaurus (orig r5985):  ribasushi | 2009-04-24 23:17:32 +0200
Wrap up order_by saga
r5994@Thesaurus (orig r5993):  arcanez | 2009-04-28 08:45:31 +0200
patch to suppress warnings in case first element of the arrayref is undef (NULL)
r5998@Thesaurus (orig r5997):  ribasushi | 2009-04-28 15:27:33 +0200
Refactor the parenthesis unroll SQLA::Test code
Allow explicit override: $SQL::Abstract::Test::parenthesis_significant
r5999@Thesaurus (orig r5998):  ribasushi | 2009-04-28 15:29:52 +0200
Add -nest tests by ldami
r6000@Thesaurus (orig r5999):  ribasushi | 2009-04-28 15:36:56 +0200
Disable t/10test.t for ordinary users (suggested by ldami)
r6001@Thesaurus (orig r6000):  dami | 2009-04-28 18:17:07 +0200
test -nest inside an arrayref
r6002@Thesaurus (orig r6001):  ribasushi | 2009-04-28 18:52:12 +0200
Parenthesis do matter in -nest tests

lib/SQL/Abstract.pm

index 3828802..57a77ba 100644 (file)
@@ -607,17 +607,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