our $PATH_NOARTIST = "NOARTIST";
our $PATH_NOALBUM = "NOALBUM";
-our $ENABLE_FILTER = 1;
+our $ENABLE_FILTER = 0;
sub new
{
{
pop @elements;
}
+# print "\nELEMENTS: ", join(' ', map { $_->name(); } @elements), "\n";
+ my @joins=$self->number_joins(@elements);
+ @joins=qw(INNER) unless(@joins);
+ $self->{joins}=\@joins;
+# print "AFTER: ", join(' ', map { $_->name() . "(" . $_->{table} . ")"; } @elements), "\n";
+# print "JOINS: ", join(', ', @joins), "\n";
# sort elements by precedence
@elements=$self->sort_elements(@elements);
$self->{tagtree}=$self->elements_to_tree(\@elements);
}
+sub number_joins
+{
+ my($self, @elements)=@_;
+ my @joins=("INNER");
+ my $table=1;
+ my $nextjoin=undef;
+ my $lastop=undef;
+ return (@joins) unless(@elements);
+ while(my $thing=shift @elements)
+ {
+ if($thing->type() == $TYPE_BOOL)
+ {
+ my $op=$thing->name();
+ if($op eq "AND")
+ {
+ $nextjoin="INNER";
+ }
+ elsif($op eq "NOT")
+ {
+ $nextjoin="LEFT";
+ }
+ elsif($op eq "OR")
+ {
+ # NOT/foo/OR needs an extra join
+ $nextjoin="INNER" if($lastop && $lastop eq "NOT");
+ }
+ $lastop=$op;
+ }
+ else
+ {
+ if(@elements)
+ {
+ # if tag has a value, eat the tag, shifting to the value
+ $thing=shift(@elements) if($elements[0]->type() == $TYPE_TAG);
+ }
+ elsif($self->{db}->tag_has_values($thing->id()))
+ {
+ # if the expression ends in a tag that has a value
+ # (ie we have the tag and want the value)
+ # use an INNER join even if we were in a NOT
+ $nextjoin="INNER" if($nextjoin);
+ }
+ if($nextjoin)
+ {
+ $table++;
+ push(@joins, $nextjoin);
+ $nextjoin=undef;
+ }
+ $thing->table($table);
+ }
+ }
+ return @joins;
+}
+
sub state
{
my($self, $newstate)=@_;
my($self)=@_;
my $hasvals=$self->expecting_values();
my $tree=$self->{tagtree};
- use Data::Dumper;
- print Dumper $tree;
+# use Data::Dumper;
+# print Dumper $tree;
my ($sqlclause, @joins)=$tree->to_sql($hasvals) if($tree);
my $sql="\tSELECT fxt1.files_id FROM tags t1";
my @crosses=();
my @inners=();
+ @joins=@{$self->{joins}};
for(my $i=0; $i <= $#joins; $i++)
{
my $cnt=$i+1;