my($tag, $tagval);
$self->{elements}=[];
$self->{bare_not}=0;
+ $self->{in_all}=0;
my $root_not=0;
my $tags_seen=0;
while(defined(my $name=shift @parts))
# print "SM: ROOT: $name\n";
if($name eq "ALL")
{
+ $self->{in_all}=1;
$self->state($STATE_ALL);
}
elsif($name eq "NOT")
{
return $self->artist_albums($tail->{id});
}
- my $sql=("SELECT albums.name\n" .
- "\tFROM (\n" .
- $self->tags_subselect() .
- "\t) AS subselect\n" .
- "INNER JOIN files ON subselect.files_id=files.id\n" .
- "INNER JOIN albums ON files.albums_id=albums.id\n" .
- "WHERE albums.name != ''\n" .
- "GROUP BY albums.name;");
+ my $sql;
+ if($self->{in_all})
+ {
+ $sql="SELECT name FROM albums";
+ }
+ else
+ {
+ $sql=("SELECT albums.name\n" .
+ "\tFROM (\n" .
+ $self->tags_subselect() .
+ "\t) AS subselect\n" .
+ "INNER JOIN files ON subselect.files_id=files.id\n" .
+ "INNER JOIN albums ON files.albums_id=albums.id\n" .
+ "WHERE albums.name != ''\n" .
+ "GROUP BY albums.name;");
+ }
print "SQL(ALBUMS): \n$sql\n";
my @names=$self->{db}->cmd_firstcol($sql);
print "ALBUMS: ", join(', ', @names), "\n";
sub artist_albums
{
my($self, $artist_id)=@_;
- my $sql=("SELECT albums.name FROM (\n" .
- $self->tags_subselect() .
- "\t) AS subselect\n" .
- "INNER JOIN files ON subselect.files_id=files.id\n" .
- "INNER JOIN albums ON albums.id=files.albums_id\n\t" .
- "INNER JOIN artists ON artists.id=files.artists_id\n\t" .
- "WHERE artists.id=? and albums.name <> ''\n\t" .
+ my $sql="SELECT albums.name FROM ";
+ if($self->{in_all})
+ {
+ $sql .= "files\n";
+ }
+ else
+ {
+ $sql .= ("(\n" .
+ $self->tags_subselect() .
+ ") AS subselect\n" .
+ "INNER JOIN files ON subselect.files_id=files.id\n");
+ }
+ $sql .= ("INNER JOIN albums ON albums.id=files.albums_id\n" .
+ "INNER JOIN artists ON artists.id=files.artists_id\n" .
+ "WHERE artists.id=? and albums.name <> ''\n" .
"GROUP BY albums.name\n");
print "ARTIST_ALBUMS SQL: $sql\n";
my @albums=$self->{db}->cmd_firstcol($sql, $artist_id);
sub artist_tracks
{
my($self, $artist_id)=@_;
- my $sql=("SELECT files.name FROM (\n" .
- $self->tags_subselect() .
- "\t) AS subselect\n" .
- "INNER JOIN files ON subselect.files_id=files.id\n" .
- "INNER JOIN artists ON artists.id=files.artists_id\n" .
+ my $sql="SELECT files.name FROM ";
+ if($self->{in_all})
+ {
+ $sql .= "files\n";
+ }
+ else
+ {
+ $sql .= ("(\n" .
+ $self->tags_subselect() .
+ "\t) AS subselect\n" .
+ "INNER JOIN files ON subselect.files_id=files.id\n");
+ }
+ $sql .= ("INNER JOIN artists ON artists.id=files.artists_id\n" .
"INNER JOIN albums ON albums.id=files.albums_id\n" .
"WHERE artists.id=? AND albums.name=''\n" .
"GROUP BY files.name\n");
sub album_tracks
{
my($self, $artist_id, $album_id)=@_;
- my $sql=("SELECT files.name FROM files\n\t" .
- "INNER JOIN albums ON albums.id=files.albums_id\n\t" .
- "INNER JOIN artists ON artists.id=files.artists_id\n\t" .
- "WHERE artists.id=? AND albums.id=?\n\t" .
+ my $sql=("SELECT files.name FROM files\n" .
+ "INNER JOIN albums ON albums.id=files.albums_id\n" .
+ "INNER JOIN artists ON artists.id=files.artists_id\n" .
+ "WHERE artists.id=? AND albums.id=?\n" .
"GROUP BY files.name\n");
print "ALBUM_TRACKS SQL($artist_id, $album_id): $sql\n";
my @names=$self->{db}->cmd_firstcol($sql, $artist_id, $album_id);
}
return $self->album_tracks($artist_id, $tail->{id});
}
- my $sql=("SELECT files.name\n" .
- "\tFROM (\n" .
- $self->tags_subselect() .
- "\t) AS subselect\n" .
- "INNER JOIN files ON files.id=subselect.files_id\n" .
- "INNER JOIN artists ON files.artists_id=artists.id\n");
+ my $sql="SELECT files.name FROM ";
+ if($self->{in_all})
+ {
+ $sql .= "files\n";
+ }
+ else
+ {
+ $sql .= ("(\n" .
+ $self->tags_subselect() .
+ ") AS subselect\n" .
+ "INNER JOIN files ON files.id=subselect.files_id\n");
+ }
+ $sql .= "INNER JOIN artists ON files.artists_id=artists.id\n";
if($self->{components}->[$#{$self->{components}}] eq "NOARTIST")
{
$sql .= "WHERE artists.name =''\n";
}
$sql .= "GROUP BY files.name;";
- print "TRACKS SQL: $sql\n";
+ print "TRACKS SQL($self->{path}): $sql\n";
my @names=$self->{db}->cmd_firstcol($sql);
print "TRACKS: ", join(', ', @names), "\n";
return(@names);
{
return $self->bare_not_subselect();
}
+ if($self->{in_all})
+ {
+ return "\tSELECT id FROM files AS files_id\n";
+ }
my $tree=$self->{tagtree};
my $hasvals=$self->tag_has_values();
my $parent=$self->trailing_tag_parent();