{
@outjoins = @joins = ("INNER");
}
+
if($self->type() ne "boolean")
{
my $cnt=scalar(@joins)+1;
}
return ($str, @outjoins);
}
- else
+
+ my $left=$self->left();
+ my $right=$self->right();
+ return ("", @outjoins) unless($left || $right);
+ my ($leftstr, @leftjoins) = $left->to_sql($hasvals, $not, @joins) if($left);
+ push(@joins, @leftjoins);
+ push(@outjoins, @leftjoins);
+ my $op=$self->name();
+ print "op: $op type: ", $self->type(), " not: $not\n";
+ if(defined($op))
{
- my $left=$self->left();
- my $right=$self->right();
- return ("", @outjoins) unless($left || $right);
- my ($leftstr, @leftjoins) = $left->to_sql($hasvals, $not, @joins) if($left);
- push(@joins, @leftjoins);
- push(@outjoins, @leftjoins);
- my $op=$self->name();
- if(defined($op) && $self->type() eq "boolean")
+ # 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 we are ANDing, add an inner join
- # also if we are NOTing, but we are looking for a tag *value*
- if( ($op eq "AND") || ($hasvals && ($op eq "NOT")))
- {
- # hack - 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")
- {
- push(@joins, "INNER");
- push(@outjoins, "INNER");
- }
- }
- elsif($op eq "NOT")
+ print "AND\n";
+ # hack - 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")
{
- $not=1;
- push(@joins, "LEFT");
- push(@outjoins, "LEFT");
-# print("LEFT: ", $left->print(), "\n") if ($left);
-# print("RIGHT: ", $right->print(), "\n") if($right);
+ push(@joins, "INNER");
+ push(@outjoins, "INNER");
}
- elsif($op eq "OR")
+ }
+ elsif($op eq "NOT")
+ {
+ print "NOT (was $not)\n";
+ $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
+ unless($right && $right->name() && $right->name() eq "NOT")
{
- # if left child is a not, we need an extra (inner) join
- if($left && $left->name() && $left->name() eq "NOT")
+ if($hasvals)
{
push(@joins, "INNER");
push(@outjoins, "INNER");
}
+ else
+ {
+ push(@joins, "LEFT");
+ push(@outjoins, "LEFT");
+ }
}
+# print("LEFT: ", $left->print(), "\n") if ($left);
+# print("RIGHT: ", $right->print(), "\n") if($right);
}
- my ($rightstr, @rightjoins) = $right->to_sql($hasvals, $not, @joins) if($right);
- push(@outjoins, @rightjoins);
-# print "LEFT (", scalar(@leftjoins), "): $leftstr\n";
-# print "RIGHT (", scalar(@rightjoins), "): $rightstr\n";
- my $str=$leftstr;
- $str .= " $op " if($op && !$not);
- $str .= $rightstr;
- if($op || ($left && $right))
+ elsif($op eq "OR")
{
- $str="(" . $str . ")";
+ print "OR\n";
+ # if left child is a NOT, we need an extra (inner) join
+ # unless right child is also a NOT
+ if(($left && $left->name() && $left->name() eq "NOT") &&
+ !($right && $right->name() && $right->name() eq "NOT"))
+ {
+ push(@joins, "INNER");
+ push(@outjoins, "INNER");
+ }
}
-# print "STR: $str\n";
-# my @all=(@joins, @rightjoins);
-# print "JOINS: RETURN ", scalar(@outjoins), " ALL ", scalar(@all), "\n";
- return($str, @outjoins);
}
+ my ($rightstr, @rightjoins) = $right->to_sql($hasvals, $not, @joins) if($right);
+ push(@outjoins, @rightjoins);
+# print "LEFT (", scalar(@leftjoins), "): $leftstr\n";
+# print "RIGHT (", scalar(@rightjoins), "): $rightstr\n";
+ $str=$leftstr;
+ $str .= " $op " if($op && !$not);
+ $str .= $rightstr;
+ if($op || ($left && $right))
+ {
+ $str="(" . $str . ")";
+ }
+# print "STR: $str\n";
+# my @all=(@joins, @rightjoins);
+# print "JOINS: RETURN ", scalar(@outjoins), " ALL ", scalar(@all), "\n";
+ return($str, @outjoins);
}
sub used_tags