From: Justin Hunter Date: Fri, 24 Apr 2009 08:03:45 +0000 (+0000) Subject: fix for x => { '!=' => [ -and => (1 .. 3) ] } X-Git-Tag: v1.70~169^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b182f72c73922f3864a15b926f945b3af0b085cb;p=dbsrgits%2FSQL-Abstract.git fix for x => { '!=' => [ -and => (1 .. 3) ] } added parens for test --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 24a1c87..5b901b0 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -360,11 +360,13 @@ sub _recurse_where { sub _where_ARRAYREF { - my ($self, $where, $logic) = @_; + my ($self, $where, $_logic) = @_; - $logic = uc($logic || $self->{logic}); + my $logic = uc($_logic || $self->{logic}); $logic eq 'AND' or $logic eq 'OR' or puke "unknown logic: $logic"; + my $orig_logic = $self->{logic}; + my @clauses = @$where; my (@sql_clauses, @all_bind); @@ -399,6 +401,7 @@ sub _where_ARRAYREF { push @all_bind, @bind; } } + $logic = $self->{logic} if $orig_logic ne $self->{logic} and !$_logic; return $self->_join_sql_clauses($logic, \@sql_clauses, \@all_bind); } @@ -584,6 +587,11 @@ sub _where_hashpair_HASHREF { }, FALLBACK => sub { # CASE: col => {op => $scalar} + if ($val =~ /^ - ( AND|OR ) $/ix) { + $self->{logic} = uc $1; + delete $v->{$op}; + return '', (); + } $sql = join ' ', $self->_convert($self->_quote($k)), $self->_sqlcase($op), $self->_convert('?'); diff --git a/t/04modifiers.t b/t/04modifiers.t index b365443..f4a0f1d 100644 --- a/t/04modifiers.t +++ b/t/04modifiers.t @@ -146,7 +146,7 @@ my @and_or_tests = ( # test column multi-cond in arrayref (even more useful) { where => { x => { '!=' => [ -and => (1 .. 3) ] } }, - stmt => 'WHERE x != ? AND x != ? AND x != ?', + stmt => 'WHERE ( ( x != ? AND x != ? AND x != ? ) )', bind => [1..3], },