1 package ID3FS::Path::Node;
9 my $class=ref($proto) || $proto;
16 $self->{parents_id}=shift;
17 if($self->{type} ne "boolean")
19 my $table=ucfirst($self->{type});
20 $table .= "s" unless($table=~/s$/);
21 $self->{id}=$db->lookup_id($table, $self->{name}, $self->{parents_id});
22 return undef unless(defined($self->{id}));
29 my($self, $name, $val)=@_;
34 return $self->{$name};
37 sub left { return shift->set("left", shift); }
38 sub right { return shift->set("right", shift); }
39 sub name { return shift->set("name", shift); }
40 sub type { return shift->set("type", shift); }
41 sub id { return shift->set("id", shift); }
42 sub parents_id { return shift->set("parents_id", shift); }
48 my $left=$self->left();
49 my $right=$self->right();
50 return "" unless($left || $right);
51 my $str .= $self->print_node($left);
52 $str .= (" " . $op . " ") if($op);
53 $str .= $self->print_node($right);
54 if($op || ($left && $right))
56 $str="(" . $str . ")";
64 return "" unless(defined($node));
65 return $node->print() if(ref($node) eq "ID3FS::Path::Node");
71 my($self, $hasvals, $not, @joins)=@_;
72 $not=0 unless(defined($not));
78 @outjoins = @joins = ("INNER");
80 if($self->type() ne "boolean")
82 my $cnt=scalar(@joins)+1;
83 $str .= "t" . scalar(@joins) . ".id='" . $self->{id} . "'";
86 $str .= " AND fxt" . scalar(@joins) . ".files_id IS NULL";
88 return ($str, @outjoins);
92 my $left=$self->left();
93 my $right=$self->right();
94 return ("", @outjoins) unless($left || $right);
95 my ($leftstr, @leftjoins) = $left->to_sql($hasvals, $not, @joins) if($left);
96 push(@joins, @leftjoins);
97 push(@outjoins, @leftjoins);
99 if(defined($op) && $self->type() eq "boolean")
101 # if we are ANDing, add an inner join
102 # also if we are NOTing, but we are looking for a tag *value*
103 if( ($op eq "AND") || ($hasvals && ($op eq "NOT")))
105 # hack - if right child is a NOT, we don't need extra join/brackets
106 # NOT will do the same and we will end up with an extra one
107 unless($right && $right->name() && $right->name() eq "NOT")
109 push(@joins, "INNER");
110 push(@outjoins, "INNER");
116 push(@joins, "LEFT");
117 push(@outjoins, "LEFT");
118 # print("LEFT: ", $left->print(), "\n") if ($left);
119 # print("RIGHT: ", $right->print(), "\n") if($right);
122 my ($rightstr, @rightjoins) = $right->to_sql($hasvals, $not, @joins) if($right);
123 push(@outjoins, @rightjoins);
124 # print "LEFT (", scalar(@leftjoins), "): $leftstr\n";
125 # print "RIGHT (", scalar(@rightjoins), "): $rightstr\n";
127 $str .= " $op " if($op && !$not);
129 if($op || ($left && $right))
131 $str="(" . $str . ")";
133 # print "STR: $str\n";
134 return($str, @outjoins);
141 if($self->type() eq "boolean")
144 push(@used, $self->left()->used_tags()) if($self->left());
145 push(@used, $self->right()->used_tags()) if($self->right());
146 return(grep { defined; } @used);