-sub node_to_sql
-{
- my($self, $node, $parent, $andlevel)=@_;
- return ("", $andlevel) unless(defined($node));
- return $node->to_sql($parent, $andlevel) if(ref($node) eq "ID3FS::Path::Node");
-# if((ref($node->op()) ne "ID3FS::Path::Element") &&
-# $node->op() eq "
- my $sql;
-# print("Hit node: " . $node->{name}. "(" .
-# (defined($node->{parents_id}) ? $node->{parents_id} : "") .
-# ")\n");
- if(defined($node->{parents_id}))
- {
-# print "HIT PARENTS_ID: $node->{parents_id}\n";
- $sql= "(t$andlevel.parents_id='$node->{parents_id}'";
- $sql .= " AND fxt${andlevel}.tags_id='" . $node->{id} . "')";
- }
-# elsif($parent)
-# {
-# print "HIT \$parent\n";
-# $sql= "(t$andlevel.parents_id='$parent')";
-# }
- else
- {
-# print "HIT NORMAL\n";
- $sql= "(t$andlevel.parents_id=''";
- $sql .= " AND fxt${andlevel}.tags_id='" . $node->{id} . "')";
- }
- return ($sql, $andlevel);
+ my $left=$self->left();
+ my $right=$self->right();
+ return ("") unless($left || $right);
+
+ my $leftstr = $left->to_sql($not) if($left);
+ my $op=$self->name();
+ $not=1 if(defined($op) && ($op eq "NOT"));
+ my $rightstr = $right->to_sql($not) if($right);
+ $str = $leftstr;
+ $str .= " $op " if($op && !$not);
+ $str .= $rightstr;
+ $str=("(" . $str . ")") if($op && $left && $right);
+ return($str);