From: Peter Rabbitson Date: Wed, 22 Dec 2010 15:45:39 +0000 (+0100) Subject: Fix stupid not exists omission X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af75bd59;p=scpubgit%2FQ-Branch.git Fix stupid not exists omission --- diff --git a/Changes b/Changes index 6ae389d..3f1e7fc 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for SQL::Abstract + - Fix parsing of NOT EXISTS + revision 1.72 2010-12-21 ---------------------------- - Extra checks of search arguments for possible SQL injection attacks diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 7b587c5..5b7b704 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -64,7 +64,7 @@ my @expression_start_keywords = ( 'ON', 'WHERE', '(?: DEFAULT \s+ )? VALUES', - 'EXISTS', + '(?:NOT \s+)? EXISTS', 'GROUP \s+ BY', 'HAVING', 'ORDER \s+ BY', @@ -379,8 +379,8 @@ sub _recurse_parse { elsif ( $token =~ /^ NOT $/ix ) { my $op = uc $token; my $right = $self->_recurse_parse ($tokens, PARSE_RHS); - $left = $left ? [ @$left, [$op => [$right] ]] - : [ $op => [$right] ]; + $left = $left ? [ @$left, [$op => [$right||()] ]] + : [ $op => [$right||()] ]; } elsif ( $token =~ $placeholder_re) { diff --git a/t/14roundtrippin.t b/t/14roundtrippin.t index 6279a76..63fb7a4 100644 --- a/t/14roundtrippin.t +++ b/t/14roundtrippin.t @@ -14,6 +14,7 @@ my @sql = ( "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a = 1 and foo.b LIKE 'station'", "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'", "SELECT [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] FROM [users_roles] [me] JOIN [roles] [role] ON [role].[id] = [me].[role_id] JOIN [roles_permissions] [role_permissions] ON [role_permissions].[role_id] = [role].[id] JOIN [permissions] [permission] ON [permission].[id] = [role_permissions].[permission_id] JOIN [permissionscreens] [permission_screens] ON [permission_screens].[permission_id] = [permission].[id] JOIN [screens] [screen] ON [screen].[id] = [permission_screens].[screen_id] WHERE ( [me].[user_id] = ? ) GROUP BY [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype]", + "SELECT * FROM foo WHERE NOT EXISTS (SELECT bar FROM baz)", ); for (@sql) {