From: Ash Berlin Date: Sat, 4 Apr 2009 16:36:47 +0000 (+0100) Subject: Make tests pass with more explicit bracketing (but still way less than old SQLA did) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39f7dc30da0d08a669cd702c0b50aeac6916fa4b;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Make tests pass with more explicit bracketing (but still way less than old SQLA did) --- diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index 53db579..0543330 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -205,7 +205,9 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { if ($_->{-type} eq 'expr' && $_->{op} =~ /^(and|or)$/) { my $sub_prio = $SQL::Abstract::PRIO{$1}; - if ($sub_prio <= $prio) { + if ($sub_prio == $prio) { + # When the element below has same priority, i.e. 'or' as a child of + # 'or', dont produce extra brackets push @output, $self->_recurse_where($_); } else { push @output, '(' . $self->_recurse_where($_) . ')'; @@ -279,10 +281,13 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { croak "between requires 3 arguments: " . dump($ast) unless @values == 2; - return $self->_expr($field) . + # The brackets are to work round an issue with SQL::A::Test + return "(" . + $self->_expr($field) . $not . " BETWEEN " . - join(" AND ", map { $self->dispatch($_) } @values ); + join(" AND ", map { $self->dispatch($_) } @values ) . + ")"; } # 'constants' that are portable across DBs diff --git a/t/100_expr_basic.t b/t/100_expr_basic.t index de43e64..0bcdaa4 100644 --- a/t/100_expr_basic.t +++ b/t/100_expr_basic.t @@ -90,7 +90,7 @@ is $sqla->dispatch( { -type => 'expr', op => 'and', args => $cols } ] } -), "me.name = ? OR me.id > ? AND me.name = ?", +), "me.name = ? OR (me.id > ? AND me.name = ?)", "expr clause (inner and)"; is $sqla->dispatch( diff --git a/t/101_expr_funcitons.t b/t/101_expr_funcitons.t index 13ec805..148f3cd 100644 --- a/t/101_expr_funcitons.t +++ b/t/101_expr_funcitons.t @@ -46,6 +46,6 @@ is $sqla->dispatch( { -type => 'value', value => 599 }, ], } -), "me.id BETWEEN ? AND ?", +), "(me.id BETWEEN ? AND ?)", "between";