fix handling of unset artist/album; unset years default to UNKNOWN
[id3fs.git] / lib / ID3FS / Path.pm
index cee1a45..46bac15 100644 (file)
@@ -132,7 +132,7 @@ sub parse
     my @parts=@{$self->{components}};
     my($tag, $tagval);
     $self->{elements}=[];
-    while(my $name=shift @parts)
+    while(defined(my $name=shift @parts))
     {
 #      print "NAME: $name\n";
        my $state=$self->state();
@@ -540,7 +540,7 @@ sub tags
        $sql .= "WHERE " . join(' AND ', @andclauses) . "\n";
     }
     $sql .= "GROUP BY tags.name;";
-    print "SQL: $sql\n";
+    print "SQL(TAGS): $sql\n";
     my @tagnames=$self->{db}->cmd_firstcol($sql);
     print "SUBNAMES: ", join(', ', @tagnames), "\n";
     return(@tagnames);
@@ -561,7 +561,7 @@ sub artists
     my($self)=@_;
     if(!@{$self->{elements}}) # /ALL
     {
-       my $sql="SELECT DISTINCT name FROM artists;";
+       my $sql="SELECT DISTINCT name FROM artists WHERE name!='';";
        return($self->{db}->cmd_firstcol($sql));
     }
     my @ids=();
@@ -570,8 +570,9 @@ sub artists
             ") AS subselect\n" .
             "INNER JOIN files ON subselect.files_id=files.id\n" .
             "INNER JOIN artists ON files.artists_id=artists.id\n" .
+            "WHERE artists.name != ''\n" .
             "GROUP BY artists.name;");
-    print "SQL: $sql\n";
+    print "SQL(ARTISTS): $sql\n";
     my @tagnames=$self->{db}->cmd_firstcol($sql);
     print "ARTISTS: ", join(', ', @tagnames), "\n";
     return(@tagnames);
@@ -593,6 +594,7 @@ sub albums
             "\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);
@@ -624,9 +626,9 @@ sub artist_tracks
             $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\t" .
-            "INNER JOIN albums  ON albums.id=files.albums_id\n\t" .
-            "WHERE artists.id=? AND albums.name=''\n\t" .
+            "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");
     print "ARTIST_TRACKS SQL: $sql\n";
     my @names=$self->{db}->cmd_firstcol($sql, $artist_id);
@@ -668,14 +670,18 @@ sub tracks
        }
        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" .
-            "GROUP BY files.name;");
-    print "SQL: $sql\n";
+            "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";
     my @names=$self->{db}->cmd_firstcol($sql);
     print "TRACKS: ", join(', ', @names), "\n";
     return(@names);
@@ -914,11 +920,4 @@ sub tags_with_values
     return $tags;
 }
 
-sub lookup_id
-{
-    my($self, $table, $name)=@_;
-    my($id)=$self->{db}->cmd_onerow("SELECT id FROM $table where name=?", $name);
-    return $id;
-}
-
 1;