From: Ash Berlin <ash_github@firemirror.com>
Date: Mon, 2 Mar 2009 09:25:27 +0000 (+0000)
Subject: Fix bracketing of where
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=865ef15a1e3be40fe5c4718587d6fff3de6c9ff0;p=dbsrgits%2FSQL-Abstract-2.0-ish.git

Fix bracketing of where
---

diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm
index 3c84192..7b18c04 100644
--- a/lib/SQL/Abstract.pm
+++ b/lib/SQL/Abstract.pm
@@ -142,7 +142,7 @@ class SQL::Abstract {
       } elsif ($op =~ /^-(and|or)$/) {
         my $sub_prio = $PRIO{$1}; 
 
-        if ($sub_prio >= $prio) {
+        if ($sub_prio <= $prio) {
           push @output, $self->_recurse_where($_);
         } else {
           push @output, '(' . $self->_recurse_where($_) . ')';
@@ -152,7 +152,7 @@ class SQL::Abstract {
       }
     }
 
-    return wantarray ? @output : join(" $OP ", @output);
+    return join(" $OP ", @output);
   }
 
   method _binop($op, $lhs, $rhs) {
diff --git a/t/001_basic.t b/t/001_basic.t
index 1322dbc..693b2fc 100644
--- a/t/001_basic.t
+++ b/t/001_basic.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 11;
 
 use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
 
@@ -63,4 +63,25 @@ is SQL::Abstract->generate(
         [ '<', [-name => qw/me name/], [-value => '100' ] ]
       ]
   ]
-), "WHERE me.id = ? OR (me.name > ? AND me.name < ?)", "where clause";
+), "WHERE me.id = ? OR me.name > ? AND me.name < ?", "where clause";
+
+is SQL::Abstract->generate(
+  [ -where =>  -and =>
+      [ '==', [-name => qw/me id/], [-value => 500 ] ],
+      [ -and => 
+        [ '>', [-name => qw/me name/], [-value => '200' ] ],
+        [ '<', [-name => qw/me name/], [-value => '100' ] ]
+      ]
+  ]
+), "WHERE me.id = ? AND me.name > ? AND me.name < ?", "where clause";
+
+
+is SQL::Abstract->generate(
+  [ -where =>  -and =>
+      [ '==', [-name => qw/me id/], [-value => 500 ] ],
+      [ -or => 
+        [ '>', [-name => qw/me name/], [-value => '200' ] ],
+        [ '<', [-name => qw/me name/], [-value => '100' ] ]
+      ]
+  ]
+), "WHERE me.id = ? AND (me.name > ? OR me.name < ?)", "where clause";