From: Peter Rabbitson Date: Sun, 9 Jun 2013 11:28:35 +0000 (+0200) Subject: Finish a RHS branch before applying ASC/DESC mods X-Git-Tag: v1.75~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c84a43217912905d7fdab027f7ca8641003665ea;hp=3cb8f017c8746fa9c688540f3e8bda09363bda09;p=dbsrgits%2FSQL-Abstract.git Finish a RHS branch before applying ASC/DESC mods --- diff --git a/Changes b/Changes index a9d3acc..94b71b1 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for SQL::Abstract + - Fix false negative comparison of ORDER BY ASC + revision 1.74 2013-06-04 ---------------------------- - Fix insufficient parenthesis unroll during operator comparison diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 5c887db..60a1aa2 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -478,6 +478,7 @@ sub _recurse_parse { # deal with post-fix operators (asc/desc) if ($tokens->[0] =~ $asc_desc_re) { + return @left if $state == PARSE_RHS; @left = [ ('-' . uc (shift @$tokens)) => [ @left ] ]; } diff --git a/t/10test.t b/t/10test.t index f3835a1..68de857 100644 --- a/t/10test.t +++ b/t/10test.t @@ -611,6 +611,13 @@ my @sql_tests = ( ], }, { + equal => 1, + statements => [ + q/ORDER BY colA, colB LIKE ? DESC, colC LIKE ?/, + q/ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC/, + ], + }, + { equal => 0, opts => { order_by_asc_significant => 1 }, statements => [ diff --git a/t/11parser.t b/t/11parser.t index 8735ffe..eaf5616 100644 --- a/t/11parser.t +++ b/t/11parser.t @@ -619,7 +619,7 @@ is_deeply($sqlat->parse("SELECT x, y FROM foo WHERE x IN (?, ?, ?, ?)"), [ ] ], 'Lists parsed correctly'); -is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? DESC, unf, baz.g / ? ASC, buzz * 0 DESC, foo DESC, ickk ASC'), [ +is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? DESC, unf, baz.g / ? ASC, buzz * 0 DESC, foo LIKE ? DESC, ickk ASC'), [ [ "SELECT", [ @@ -776,11 +776,22 @@ is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? D "-DESC", [ [ - "-LITERAL", + "LIKE", [ - "foo" - ] - ] + [ + "-LITERAL", + [ + "foo" + ] + ], + [ + "-PLACEHOLDER", + [ + "?" + ] + ], + ], + ], ] ], [ @@ -1109,19 +1120,16 @@ is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz) ], ], [ - "max", - [ - [ "-DESC", [ [ "-MISC", [ [ - "-MISC", + "-DESC", [ [ - "-DESC", + "max", [ [ "-PAREN", @@ -1134,22 +1142,20 @@ is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz) ] ] ] - ] - ], - [ - "-LITERAL", - [ - "x" - ] - ], + ], + ] ] ], [ "-LITERAL", [ - "z" + "x" ] - ] + ], + [ + "-LITERAL", + [ + "z" ] ] ]