- my @ids=();
- my $main_sql_start=("SELECT artists.name\n" .
- "\tFROM (SELECT files_id FROM tags\n" .
- "\t\tINNER JOIN files_x_tags ON tags.id=files_x_tags.tags_id\n" .
- "\t\tWHERE tags.id in\n\t\t\t(");
- my $main_sql_end=(")\n\t\t) AS subselect\n" .
- "\tINNER JOIN files_x_artists ON subselect.files_id=files_x_artists.files_id\n" .
- "\tINNER JOIN artists ON artists.id=files_x_artists.artists_id\n" .
- "\n\tGROUP BY artists.name;");
- while(my $constraint=shift @constraints)
- {
- print "CONSTRAINT: $constraint->{name}\n";
- my $cid=$constraint->{id};
- push(@ids, $cid);
- }
- @ids = map( { "\"$_\""; } @ids) unless($self->{postgres});
- my $tagstr=join(", ", @ids);
- my $sql = ($main_sql_start . $tagstr .
- $main_sql_end);
- print "SQL: $sql\n";
- my $result=$self->cmd_rows($sql);
- my @tagnames=map { $_->[0]; } @$result;
- print "ARTISTS: ", join(', ', @tagnames), "\n";
- return(@tagnames);
-}
-
-sub albums
-{
- my($self, @constraints)=@_;
- my @ids=();
- # FIXME: rework PathElements
- if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Artist")
- {
- return $self->artist_albums($constraints[$#constraints]->{id});
- }
- my $main_sql_start=("SELECT albums.name\n" .
- "\tFROM (SELECT files_id FROM tags\n" .
- "\t\tINNER JOIN files_x_tags ON tags.id=files_x_tags.tags_id\n" .
- "\t\tWHERE tags.id in\n\t\t\t(");
- my $main_sql_end=(")\n\t\t) AS subselect\n" .
- "\tINNER JOIN files_x_albums ON subselect.files_id=files_x_albums.files_id\n" .
- "\tINNER JOIN albums ON albums.id=files_x_albums.albums_id\n" .
- "\n\tGROUP BY albums.name;");
- while(my $constraint=shift @constraints)
- {
- print "CONSTRAINT: $constraint->{name}\n";
- my $cid=$constraint->{id};
- push(@ids, $cid);
- }
- @ids = map( { "\"$_\""; } @ids) unless($self->{postgres});
- my $str=join(", ", @ids);
- my $sql = ($main_sql_start . $str .
- $main_sql_end);
- print "SQL: $sql\n";
- my $result=$self->cmd_rows($sql);
- my @names=map { $_->[0]; } @$result;
- print "ALBUMS: ", join(', ', @names), "\n";
- return(@names);
-}
-
-sub artist_albums
-{
- my($self, $artist_id)=@_;
- my $sql=("SELECT albums.name FROM artists\n\t" .
- "INNER JOIN artists_x_albums ON artists.id=artists_x_albums.artists_id\n\t" .
- "INNER JOIN albums ON albums.id=artists_x_albums.albums_id\n\t" .
- "WHERE artists.id=?\n\t" .
- "GROUP BY albums.name\n");
- print "ARTIST_ALBUMS SQL: $sql\n";
- my $result=$self->cmd_rows($sql, $artist_id);
- my @albums=map { $_->[0]; } @$result;
- print "ALBUMS: ", join(', ', @albums), "\n";
- return(@albums);
-}
-
-sub artist_tracks
-{
- my($self, $artist_id)=@_;
- my $sql=("SELECT files.name FROM artists\n\t" .
- "INNER JOIN artists_x_files ON artists.id=files_x_artists.artists_id\n\t" .
- "INNER JOIN files ON files.id=files_x_artists.files_id\n\t" .
- "WHERE artists.id=?\n\t" .
- "GROUP BY files.name\n");
- print "ARTIST_TRACKS SQL: $sql\n";
- my $result=$self->cmd_rows($sql, $artist_id);
- my @names=map { $_->[0]; } @$result;
- @names = map { s/.*\///; } @names;
- print "ARTISTTRACKS: ", join(', ', @names), "\n";
- return(@names);