# print "DIRENTS: FILE: $self->{path}\n";
if($state==$STATE_ALL)
{
- push(@dents, $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
+ @dents=($self->artists(), $PATH_ALLTRACKS, $PATH_NOARTIST);
}
elsif($state==$STATE_TAG || $state==$STATE_TAGVAL)
{
}
else
{
- push(@dents, qw(AND OR), $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
+ @dents=($self->artists(), qw(AND OR), $PATH_ALLTRACKS, $PATH_NOARTIST);
}
}
elsif($state==$STATE_BOOLEAN)
{
+ @dents=$self->tags();
my $parent=$self->tail();
unless(defined($parent) &&
ref($parent) eq "ID3FS::PathElement::Boolean" &&
{
push(@dents, "NOT");
}
- push(@dents, $self->tags());
}
elsif($state==$STATE_ROOT)
{
- @dents=(qw(ALL NOT), $self->tags());
+ @dents=($self->tags(), qw(ALL NOT));
}
elsif($state==$STATE_ALBUMS)
{
- @dents=($PATH_ALLTRACKS, $PATH_NOALBUM, $self->albums());
+ @dents=($self->albums(), $PATH_ALLTRACKS, $PATH_NOALBUM);
}
elsif($state==$STATE_TRACKLIST)
{
return($self->{tagtree}->used_tags());
}
-sub tag_has_values
+sub expecting_values
{
my($self)=@_;
my $tail=$self->tail();
my $sql="SELECT DISTINCT name FROM tags WHERE parents_id='';";
return($self->{db}->cmd_firstcol($sql));
}
- my $hasvals=$self->tag_has_values();
+ my $hasvals=$self->expecting_values();
my $parent=$self->trailing_tag_parent();
# print "THASVALS: $hasvals\n";
# print "TPARENT: ", (defined($parent)? $parent : "NO"), "\n";
return(@tagnames);
}
-sub tag_values
-{
- my($self, $tagid)=@_;
- my $sql=("SELECT DISTINCT name FROM tags\n" .
- "WHERE parents_id=?");
- my @tags=$self->{db}->cmd_firstcol($sql, $tagid);
- @tags=map { length($_) ? $_ : "NOVALUE"; } @tags;
- return @tags;
-}
-
sub artists
{
my($self)=@_;
sub tags_subselect
{
my($self)=@_;
- my $hasvals=$self->tag_has_values();
+ my $hasvals=$self->expecting_values();
# we need to specially handle a bare /NOT/tag with no other clauses,
# using a simple WHERE id !='tagid' instead of a LEFT JOIN
if($self->{bare_not})
return($sql);
}
-sub tags_subselect_and_not
-{
- my($self,@constraints)=@_;
- my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
- my @tags=@$tags;
- my @tags_vals=@$tags_vals;;
- my $cnt=1;
- my @andclauses=();
- my $sql='';
- for my $tag (@tags)
- {
- if($cnt == 1)
- {
- $sql="\tSELECT fxt" . scalar(@tags) . ".files_id FROM files_x_tags fxt1\n";
- push(@andclauses, "\t\tfxt${cnt}.tags_id=$tag");
- }
- else
- {
- $sql .= ("\tLEFT JOIN files_x_tags fxt$cnt ON fxt" .
- ($cnt-1) . ".files_id=fxt${cnt}.files_id\n");
- push(@andclauses, "\t\tfxt${cnt}.tags_id IS NULL");
- }
- print "AND: @andclauses\n";
- $cnt++;
- }
- if(@andclauses)
- {
- $sql .= "\tWHERE\n\t\t";
- $sql .= join(" AND\n\t\t", @andclauses) . "\n";
- }
- $sql .= "\tGROUP BY fxt". scalar(@tags).".files_id\n";
- return $sql;
-}
-
-
-sub tags_subselect_and
-{
- my($self,@constraints)=@_;
- my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
- my @tags=@$tags;
- my @tags_vals=@$tags_vals;;
- my $cnt=1;
- my @andclauses=();
- my $sql='';
- for my $tag (@tags)
- {
- if($cnt == 1)
- {
- $sql="\tSELECT fxt" . scalar(@tags) . ".files_id FROM files_x_tags fxt1\n";
- }
- else
- {
- $sql .= ("\tINNER JOIN files_x_tags fxt$cnt ON fxt" .
- ($cnt-1) . ".files_id=fxt${cnt}.files_id\n");
- }
- push(@andclauses, "\t\tfxt${cnt}.tags_id = $tag");
- print "AND: @andclauses\n";
- $cnt++;
- }
- if(@andclauses)
- {
- $sql .= "\tWHERE\n\t\t";
- $sql .= join(" AND\n\t\t", @andclauses) . "\n";
- }
- $sql .= "\tGROUP BY fxt". scalar(@tags).".files_id\n";
- return $sql;
-}
-
-sub tags_subselect_or
-{
- my($self,@constraints)=@_;
- my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
- my @tags=@$tags;
- my @tags_vals=@$tags_vals;;
-
- my $sql=("\tSELECT files_x_tags.files_id FROM tags t1\n" .
- "\tINNER JOIN files_x_tags ON t1.id=files_x_tags.tags_id\n");
- my @orclauses=();
- my @andclauses=();
- # FIXME: and / or?
- if(@tags)
- {
- push(@andclauses, "( t1.parents_id=" . (defined($parent) ? $parent : "''") . " )");
- push(@andclauses, "( t1.id IN ( " . join(', ', @tags) ." ) )");
- }
- for my $pair (@tags_vals)
- {
- my($tag, $val)=@$pair;
- push(@orclauses, "( t1.parents_id=$tag AND t1.id=$val )");
- }
-# push(@andclauses, "( t1.parents_id=" . (defined($parent) ? $parent : "''") . " )");
- if(@orclauses)
- {
- push(@andclauses, join("\n\t\tOR ", @orclauses));
- }
- if(@andclauses)
- {
- $sql .= "\tWHERE\n\t\t";
- $sql .= join("\n\t\tAND ", @andclauses) . "\n";
- }
- $sql .= "\tGROUP BY files_x_tags.files_id\n";
- return $sql;
-}
-
sub constraints_tag_list
{
my($self, @constraints)=@_;
my $maxdepth=4;
for my $dir (@dirs)
{
-# print "FILTER (",$self->state(), "): $base / $dir\n";
+# print "\nFILTER (",$self->state(), "): $base / $dir\n";
if($self->empty("$base/$dir", $maxdepth))
{
# print "empty: $base / $dir\n";
}
else
{
-# print "accepting: $base / $dir\n";
+# print "non-empty, accepting: $base / $dir\n";
push(@outdirs, $dir);
}
}
sub empty
{
my($self, $dir, $maxdepth)=@_;
- return 1 unless($maxdepth);
+ return 0 unless($maxdepth);
# print "testing($maxdepth): $dir\n";
my $path=ID3FS::Path->new($self->{db}, $dir, $self->{verbose});
# print "PATH INVALID\n" unless($path->isvalid());
return 1;
}
-sub tagname_has_values
-{
- my($self, $name)=@_;
- my $id=$self->{db}->lookup_id("tags", $name);
- return 0 unless($id);
- return $self->{db}->tag_has_values($id);
-
-}
-
sub dir_is_special
{
my($self, $dir)=@_;
- if((grep { $_ eq $dir; }
- qw(AND OR NOT), $PATH_ALLTRACKS, $PATH_NOARTIST, $PATH_NOALBUM) ||
- ($self->tagname_has_values($dir)))
+ my $id=$self->{db}->lookup_id("tags", $dir);
+ if((grep { $_ eq $dir; } (qw(AND OR NOT), $PATH_ALLTRACKS,
+ $PATH_NOARTIST, $PATH_NOALBUM)) ||
+ ($id && $self->{db}->tag_has_values($id)))
{
return 1;
}