From 718b120fd81446b15dcf83bc16ab8af5cb642fb1 Mon Sep 17 00:00:00 2001 From: Ian Beckwith Date: Tue, 19 Oct 2010 22:16:15 +0100 Subject: [PATCH] join stack tweaking --- lib/ID3FS/Path/Node.pm | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/ID3FS/Path/Node.pm b/lib/ID3FS/Path/Node.pm index 720d12f..b71406d 100644 --- a/lib/ID3FS/Path/Node.pm +++ b/lib/ID3FS/Path/Node.pm @@ -98,29 +98,26 @@ sub to_sql my $op=$self->name(); if(defined($op)) { - my $left_is_not =($left && $left->name() && $left->name() eq "NOT"); - my $right_is_not=($right && $right->name() && $right->name() eq "NOT"); my $join=undef; - # if we are ANDing, add an inner join - # also if we are NOTing, but we are looking for a tag *value* - if($op eq "AND") + # if right child is a NOT, we don't need extra join/brackets + # NOT will do the same and we will end up with an extra one + unless($right && $right->name() && $right->name() eq "NOT") { - # if right child is a NOT, we don't need extra join/brackets - # NOT will do the same and we will end up with an extra one - $join= "INNER" unless($right_is_not); - } - elsif($op eq "NOT") - { - $not=1; - # as above - if right child is a NOT, we don't need extra join/brackets - # NOT will do the same and we will end up with an extra one - $join = ($hasvals ? "INNER" : "LEFT") unless($right_is_not); - } - elsif($op eq "OR") - { - # if left child is a NOT, we need an extra (inner) join - # unless right child is also a NOT - $join="INNER" if($left_is_not && ! $right_is_not) + # if we are ANDing or ORing, add an inner join + # also if we are NOTing, but we are looking for a tag *value* + if($op eq "AND") + { + $join= "INNER"; + } + elsif($op eq "NOT") + { + $not=1; + $join = ($hasvals ? "INNER" : "LEFT"); + } + elsif($op eq "OR") + { + $join="INNER" unless($left && $left->name() && $left->name() eq "NOT") + } } if($join) { -- 2.11.0