From: Peter Rabbitson Date: Fri, 11 May 2012 04:47:09 +0000 (+0200) Subject: Fix false-negative function comparisons X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1de1d085963125cb63f6a0986a9984470ff6f74b;p=scpubgit%2FQ-Branch.git Fix false-negative function comparisons --- diff --git a/Changes b/Changes index a7cc7fc..7c5a4a8 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for SQL::Abstract - Add support for NULLS FIRST/LAST in ORDER BY + - Fix insufficient parenthesis unroll during operator comparison revision 1.73 2012-07-10 ---------------------------- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index dedd8f3..54dfd62 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -731,6 +731,23 @@ sub _parenthesis_unroll { $changes++; } + # a construct of ... ( somefunc ( ... ) ) ... can safely lose the outer parens + # except for the case of ( NOT ( ... ) ) which has already been handled earlier + elsif ( + @{$child->[1]} == 1 + and + @{$child->[1][0][1]} == 1 + and + $child->[1][0][0] ne 'NOT' + and + ref $child->[1][0][1][0] eq 'ARRAY' + and + $child->[1][0][1][0][0] eq '-PAREN' + ) { + push @children, @{$child->[1]}; + $changes++; + } + # otherwise no more mucking for this pass else { diff --git a/t/10test.t b/t/10test.t index 9c69343..6e4259f 100644 --- a/t/10test.t +++ b/t/10test.t @@ -711,7 +711,26 @@ my @sql_tests = ( 'WHERE ( foo GLOB ? )', 'WHERE foo GLOB ?', ], - } + }, + { + equal => 1, + statements => [ + 'SELECT FIRST ? SKIP ? [me].[id], [me].[owner] + FROM [books] [me] + WHERE ( ( (EXISTS ( + SELECT FIRST ? SKIP ? [owner].[id] + FROM [owners] [owner] + WHERE ( [books].[owner] = [owner].[id] ) + )) AND [source] = ? ) )', + 'SELECT FIRST ? SKIP ? [me].[id], [me].[owner] + FROM [books] [me] + WHERE ( ( EXISTS ( + SELECT FIRST ? SKIP ? [owner].[id] + FROM [owners] [owner] + WHERE ( [books].[owner] = [owner].[id] ) + ) AND [source] = ? ) )', + ], + }, ); my @bind_tests = (