OR: show all unused tags
authorIan Beckwith <ianb@erislabs.net>
Tue, 19 Oct 2010 04:38:12 +0000 (05:38 +0100)
committerIan Beckwith <ianb@erislabs.net>
Tue, 19 Oct 2010 04:38:12 +0000 (05:38 +0100)
lib/ID3FS/Path.pm

index e99a801..4cf5fc2 100644 (file)
@@ -504,11 +504,19 @@ sub tags
 #    print "THASVALS: $hasvals\n";
 #    print "TPARENT: ", (defined($parent)? $parent : "NO"), "\n";
     my @ids=();
-    my $sql=("SELECT tags.name FROM (\n" .
-            $self->tags_subselect() .
-            ") AS subselect\n" .
-            "INNER JOIN files_x_tags ON subselect.files_id=files_x_tags.files_id\n" .
-            "INNER JOIN tags ON files_x_tags.tags_id=tags.id\n");
+    my $sql="SELECT tags.name FROM ";
+    if($self->in_or())
+    {
+       $sql .= "files_x_tags\n";
+    }
+    else
+    {
+       $sql .= ("(\n" .
+                $self->tags_subselect() .
+                ") AS subselect\n" .
+                "INNER JOIN files_x_tags ON subselect.files_id=files_x_tags.files_id\n");
+    }
+    $sql .= "INNER JOIN tags ON files_x_tags.tags_id=tags.id\n";
     my @andclauses=();
     my $id=$self->trailing_tag_id();
 
@@ -679,6 +687,8 @@ sub tags_subselect
     my $hasvals=$self->expecting_values();
     if($self->{in_all})
     {
+       # FIXME: is this used?
+       die "IN_ALL CALLED!!\n";
        return "\tSELECT id FROM files AS files_id\n";
     }
     my $tree=$self->{tagtree};
@@ -743,7 +753,7 @@ sub sql_start
     return $sql;
 }
 
-
+# FIXME: remove
 sub constraints_tag_list
 {
     my($self, @constraints)=@_;
@@ -814,4 +824,20 @@ sub empty
     return 1;
 }
 
+# if path is .../OR/ or .../OR/NOT
+sub in_or
+{
+    my($self)=@_;
+    my $tail=$self->tail();
+    return 0 unless($tail);
+    return 0 unless($tail->type() eq "boolean");
+    return 1 if($tail->name() eq "OR");
+    return 0 unless($tail->name() eq "NOT");
+    my $parent=$self->tail_parent();
+    return 0 unless($parent);
+    return 0 unless($parent->type() eq "boolean");
+    return 1 if($parent->name() eq "OR");
+    return 0;
+}
+
 1;