sub tag_values
{
- my($self, $tag)=@_;
- my $sql=("SELECT DISTINCT tagvals.name FROM tags\n" .
- "INNER JOIN tags_x_tagvals ON tags.id=tags_x_tagvals.tags_id\n" .
- "INNER JOIN tagvals ON tagvals.id=tags_x_tagvals.tagvals_id\n" .
- "WHERE tags.name=?");
- my $tags=$self->cmd_rows($sql, $tag);
- return(map { $_->[0]; } @$tags);
+ my($self, $tagid)=@_;
+ my $sql=("SELECT DISTINCT tagvals.name FROM tagvals\n" .
+ "INNER JOIN tags_x_tagvals ON tagvals.id=tags_x_tagvals.tagvals_id\n" .
+ "WHERE tags_x_tagvals.tags_id=?");
+ my $tags=$self->cmd_rows($sql, $tagid);
+ my @tags=map { $_->[0]; } @$tags;
+ # FIXME: handle when indexing, not here
+ @tags=map { s/[^[:print:]]//g; $_; } @tags;
+ @tags=map { length($_) ? $_ : "NOVALUE"; } @tags;
+ return @tags;
}
sub artists
return $id;
}
+sub tag_has_values
+{
+ my($self, $id)=@_;
+ my $sql=("SELECT COUNT(*) FROM tags\n\t" .
+ "INNER JOIN tags_x_tagvals ON tags.id=tags_x_tagvals.tags_id\n\t" .
+ "INNER JOIN tagvals ON tagvals.id=tags_x_tagvals.tagvals_id\n\t" .
+ "WHERE tags.id=?\n");
+ my ($rows)=$self->cmd_onerow($sql, $id);
+ return $rows;
+}
+
sub relation_exists
{
my ($self, $relname, $fields)=@_;
{
when($STATE_TAG)
{
- @dents=(qw(AND ALLTRACKS), # FIXME: NOT and OR
- $self->{db}->artists(@{$self->{elements}}));
+ my $tag=$self->{elements}->[$#{$self->{elements}}];
+ if(defined($tag) && (ref($tag) eq "ID3FS::PathElement::Tag") &&
+ $self->{db}->tag_has_values($tag->{id}))
+ {
+ print "DIRENTS: TAG: TAGVALUES\n";
+ @dents=$self->{db}->tag_values($tag->{id});
+ }
+ else
+ {
+ print "DIRENTS: TAG: ARTISTS\n";
+ @dents=(qw(AND ALLTRACKS), # FIXME: NOT and OR
+ $self->{db}->artists(@{$self->{elements}}));
+ }
}
when($STATE_BOOLEAN)
{
when($STATE_ROOT)
{
@dents=("ALL", $self->{db}->tags(@{$self->{elements}}));
- print "\nDIRENTS: DENTS: ", join(", ", @dents),"\n\n";
}
when($STATE_ALBUMS)
{
when($STATE_TAG)
{
print "SM: TAG: $name\n";
- given($name)
+ my $tag=$self->{elements}->[$#{$self->{elements}}];
+ if(defined($tag) &&
+ ref($tag) eq "ID3FS::PathElement::Tag" &&
+ $self->{db}->tag_has_values($tag->{id}))
{
- when("AND")
+ my $tagval=ID3FS::PathElement::Tagval->new($name);
+ if(defined($tagval))
{
$self->state($STATE_BOOLEAN);
-# push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+ push(@{$self->{elements}}, $tagval);
}
- when("ALLTRACKS")
- {
- $self->state($STATE_TRACKLIST);
- }
- when("OR")
+ else
{
- $self->state($STATE_BOOLEAN);
-# push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+ $self->state($STATE_INVALID);
}
- when("NOT")
+ }
+ else
+ {
+ given($name)
{
- $self->state($STATE_TAG);
+ when("AND")
+ {
+ $self->state($STATE_BOOLEAN);
+# push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+ }
+ when("ALLTRACKS")
+ {
+ $self->state($STATE_TRACKLIST);
+ }
+ when("OR")
+ {
+ $self->state($STATE_BOOLEAN);
+# push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
+ }
+ when("NOT")
+ {
+ $self->state($STATE_TAG);
# push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($name));
- }
- my $artist=ID3FS::PathElement::Artist->new($self->{db}, $name);
- if($artist)
- {
- push(@{$self->{elements}}, $artist);
- $self->state($STATE_ALBUMS);
- }
- else
- {
- $self->state($STATE_INVALID);
+ }
+ my $artist=ID3FS::PathElement::Artist->new($self->{db}, $name);
+ if($artist)
+ {
+ push(@{$self->{elements}}, $artist);
+ $self->state($STATE_ALBUMS);
+ }
+ else
+ {
+ $self->state($STATE_INVALID);
+ }
}
}
}