use strict;
use warnings;
-use ID3FS::PathElement::Artist;
-use ID3FS::PathElement::Album;
-use ID3FS::PathElement::Boolean;
-use ID3FS::PathElement::File;
-use ID3FS::PathElement::Tag;
-use ID3FS::PathElement::Tagval;
use ID3FS::Path::Node;
our ($STATE_INVALID, $STATE_ROOT, $STATE_TAG, $STATE_TAGVAL,
my @parts=@{$self->{components}};
my($tag, $tagval);
$self->{elements}=[];
- $self->{bare_not}=0;
$self->{in_all}=0;
my $root_not=0;
my $tags_seen=0;
elsif($name eq "NOT")
{
$root_not=1;
- push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($self->{db}, $name));
+ push(@{$self->{elements}}, ID3FS::Path::Node->new($self->{db}, "boolean", $name));
$self->state($STATE_BOOLEAN);
}
else
{
- $tag=ID3FS::PathElement::Tag->new($self->{db}, $name);
+ $tag=ID3FS::Path::Node->new($self->{db},"tag", $name);
if($tag)
{
push(@{$self->{elements}}, $tag);
$self->{db}->tag_has_values($tag->id()))
{
# print "Parsing: parent: $tag->id()\n";
- my $tagval=ID3FS::PathElement::Tag->new($self->{db}, $name, $tag->id());
+ my $tagval=ID3FS::Path::Node->new($self->{db}, "tag", $name, $tag->id());
if(defined($tagval))
{
$self->state($STATE_TAGVAL);
elsif($name eq "AND")
{
$self->state($STATE_BOOLEAN);
- push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($self->{db}, $name));
+ push(@{$self->{elements}}, ID3FS::Path::Node->new($self->{db}, "boolean", $name));
}
elsif($name eq "OR")
{
$self->state($STATE_BOOLEAN);
- push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($self->{db}, $name));
+ push(@{$self->{elements}}, ID3FS::Path::Node->new($self->{db}, "boolean", $name));
}
else
{
- my $artist=ID3FS::PathElement::Artist->new($self->{db}, $name);
+ my $artist=ID3FS::Path::Node->new($self->{db}, "artist", $name);
if($artist)
{
push(@{$self->{elements}}, $artist);
if($allownot && $name eq "NOT")
{
$self->state($STATE_BOOLEAN);
- push(@{$self->{elements}}, ID3FS::PathElement::Boolean->new($self->{db}, $name));
+ push(@{$self->{elements}}, ID3FS::Path::Node->new($self->{db}, "boolean", $name));
}
else
{
- my $tag=ID3FS::PathElement::Tag->new($self->{db}, $name);
+ my $tag=ID3FS::Path::Node->new($self->{db}, "tag", $name);
if($tag)
{
push(@{$self->{elements}}, $tag);
}
else
{
- my $album=ID3FS::PathElement::Album->new($self->{db}, $name);
+ my $album=ID3FS::Path::Node->new($self->{db}, "album", $name);
if($album)
{
push(@{$self->{elements}}, $album);
elsif($state==$STATE_TRACKLIST)
{
# print "SM: TRACKLIST: $name\n";
- my $track=ID3FS::PathElement::File->new($self->{db}, $name);
+ my $track=ID3FS::Path::Node->new($self->{db}, "file", $name);
if($track)
{
push(@{$self->{elements}}, $track);
}
else
{
- my $artist=ID3FS::PathElement::Artist->new($self->{db}, $name);
+ my $artist=ID3FS::Path::Node->new($self->{db}, "artist", $name);
if($artist)
{
push(@{$self->{elements}}, $artist);
}
}
- if($root_not && ($tags_seen < 2))
- {
- $self->{bare_not}=1;
- }
-
# remove trailing boolean
my @elements=@{$self->{elements}};
while(@elements && $self->is("boolean", $elements[$#elements]))
$self->{tagtree}=$self->elements_to_tree(\@elements);
if($self->{tagtree})
{
- ($self->{sqlconditions},
- $self->{joins}) = $self->{tagtree}->to_sql();
-# print "TREE: ", $self->{tagtree}->print(), "\n";
-# print("SQL CONDITION(", scalar(@{$self->{joins}}), "): ",
-# $self->{sqlconditions}, "\n");
-# use Data::Dumper;
-# print Dumper $self->{tagtree};
+# my ($conditions, @joins)=$self->{tagtree}->to_sql();
+# print "CONDITIONS(", scalar(@joins), "): ", $conditions, "\n";
}
}
my $thing=pop @$elements;
if($self->is("boolean", $thing))
{
- my $op=$thing;
$right=$self->elements_to_tree($elements);
- if($op->{name} ne "NOT")
+ if($thing->{name} ne "NOT")
{
$left=$self->elements_to_tree($elements);
}
- return ID3FS::Path::Node->new($left, $op, $right);
- }
- else
- {
- return ID3FS::Path::Node->new($thing);
+ $thing->left($left);
+ $thing->right($right);
}
+ return $thing;
}
# Dijkstra's shunting-yard algorithm
{
my($self, $type, $thing)=@_;
return 0 unless($thing);
- my $ref=ref($thing);
- my $typestr="ID3FS::PathElement::" . ucfirst($type);
- return 1 if($ref eq $typestr);
+ return 0 unless($thing->type());
+ return 1 if($type eq $thing->type());
return 0;
}
my($self)=@_;
my @ids=();
my $tail=$self->tail();
- # FIXME: rework PathElements
if($self->is("artist", $tail))
{
return $self->artist_albums($tail->id());
sub tracks
{
my($self)=@_;
- # FIXME: rework PathElements
my $tail=$self->tail();
if($self->is("artist", $tail))
{
{
my($self)=@_;
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 $self->bare_not_subselect();
- }
if($self->{in_all})
{
return "\tSELECT id FROM files AS files_id\n";
}
my $tree=$self->{tagtree};
+ print "UNDEF!!\n" unless($self->{tagtree});
my $parent=$self->trailing_tag_parent();
# print "ELEMENTS: ", join('/', map { $_->{name}; } @{$self->{elements}}), "\n";
return $sql;
}
-sub bare_not_subselect
-{
- my($self)=@_;
- my @tags=grep { $self->is("tag", $_); } @{$self->{elements}};
- my $sql=("\tSELECT f1.id AS files_id FROM files f1 WHERE f1.id NOT IN (\n" .
- "\t\tSELECT fxt1.files_id FROM tags t1\n" .
- "\t\tINNER JOIN files_x_tags fxt1 ON t1.id=fxt1.tags_id\n" .
- "\t\tWHERE ");
- if(scalar(@tags) > 1)
- {
- $sql .= ("(t1.parents_id='" . $tags[0]->id() . "' AND t1.id='" .
- $tags[1]->id() . "')");
- }
- else
- {
- $sql .= ("(t1.parents_id='' AND t1.id='" . $tags[0]->id() . "')");
- }
- $sql .= "\n\t\tGROUP BY fxt1.files_id\n\t)\n";
- return($sql);
-}
-
sub sql_start
{
my($self, $tables)=@_;
my @outdirs=();
for my $dir (@dirs)
{
- print "\nFILTER (",$self->state(), "): $base / $dir\n";
+# print "\nFILTER (",$self->state(), "): $base / $dir\n";
if($self->empty("$base/$dir"))
{
- print "empty: $base / $dir\n";
+# print "empty: $base / $dir\n";
}
else
{
- print "non-empty, accepting: $base / $dir\n";
+# print "non-empty, accepting: $base / $dir\n";
push(@outdirs, $dir);
}
}