- print "op: $op type: ", $self->type(), " not: $not\n";
- if(defined($op))
- {
- # 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")
- {
- 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")
- {
- push(@joins, "INNER");
- push(@outjoins, "INNER");
- }
- }
- 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($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);
- }
- elsif($op eq "OR")
- {
- 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");
- }
- }
- }
- 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;