1 # id3fs - a FUSE-based filesystem for browsing audio metadata
2 # Copyright (C) 2010 Ian Beckwith <ianb@erislabs.net>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package ID3FS::Path::Node;
25 my $class=ref($proto) || $proto;
32 $self->{parents_id}=shift;
33 if($self->{type} ne "boolean")
35 my $table=ucfirst($self->{type});
36 $table .= "s" unless($table=~/s$/);
37 $self->{id}=$db->lookup_id($table, $self->{name}, $self->{parents_id});
38 return undef unless(defined($self->{id}));
45 my($self, $name, $val)=@_;
50 return $self->{$name};
53 sub left { return shift->set("left", shift); }
54 sub right { return shift->set("right", shift); }
55 sub name { return shift->set("name", shift); }
56 sub type { return shift->set("type", shift); }
57 sub id { return shift->set("id", shift); }
58 sub parents_id { return shift->set("parents_id", shift); }
62 my($self, $hasvals, $not, @joins)=@_;
63 $not=0 unless(defined($not));
69 @outjoins = @joins = ("INNER");
72 if($self->type() ne "boolean")
74 my $cnt=scalar(@joins)+1;
75 $str .= "t" . scalar(@joins) . ".id='" . $self->{id} . "'";
78 $str .= " AND fxt" . scalar(@joins) . ".files_id IS NULL";
80 return ($str, @outjoins);
83 my $left=$self->left();
84 my $right=$self->right();
85 return ("", @outjoins) unless($left || $right);
86 my ($leftstr, @leftjoins) = $left->to_sql($hasvals, $not, @joins) if($left);
87 push(@joins, @leftjoins);
88 push(@outjoins, @leftjoins);
90 print "op: $op type: ", $self->type(), " not: $not\n";
93 # if we are ANDing, add an inner join
94 # also if we are NOTing, but we are looking for a tag *value*
98 # hack - if right child is a NOT, we don't need extra join/brackets
99 # NOT will do the same and we will end up with an extra one
100 unless($right && $right->name() && $right->name() eq "NOT")
102 push(@joins, "INNER");
103 push(@outjoins, "INNER");
108 print "NOT (was $not)\n";
110 # as above - if right child is a NOT, we don't need extra join/brackets
111 # NOT will do the same and we will end up with an extra one
112 unless($right && $right->name() && $right->name() eq "NOT")
116 push(@joins, "INNER");
117 push(@outjoins, "INNER");
121 push(@joins, "LEFT");
122 push(@outjoins, "LEFT");
129 # if left child is a NOT, we need an extra (inner) join
130 # unless right child is also a NOT
131 if(($left && $left->name() && $left->name() eq "NOT") &&
132 !($right && $right->name() && $right->name() eq "NOT"))
134 push(@joins, "INNER");
135 push(@outjoins, "INNER");
139 my ($rightstr, @rightjoins) = $right->to_sql($hasvals, $not, @joins) if($right);
140 push(@outjoins, @rightjoins);
141 # print "LEFT (", scalar(@leftjoins), "): $leftstr\n";
142 # print "RIGHT (", scalar(@rightjoins), "): $rightstr\n";
144 $str .= " $op " if($op && !$not);
146 if($op || ($left && $right))
148 $str="(" . $str . ")";
150 # print "STR: $str\n";
151 # my @all=(@joins, @rightjoins);
152 # print "JOINS: RETURN ", scalar(@outjoins), " ALL ", scalar(@all), "\n";
153 return($str, @outjoins);
159 if($self->type() eq "boolean")
162 push(@used, $self->left()->used_tags()) if($self->left());
163 push(@used, $self->right()->used_tags()) if($self->right());
164 return(grep { defined; } @used);