sub used_tags
{
my($self)=@_;
- print "TAGTREE UNDEF\n" unless(defined($self->{tagtree}));
- return undef unless(defined($self->{tagtree}));
+ return() unless(defined($self->{tagtree}));
return($self->{tagtree}->used_tags());
}
sub tags
{
my($self)=@_;
- if(!@{$self->{elements}}) # /
+ if(!$self->{tagtree}) # / or /NOT
{
my $sql="SELECT DISTINCT name FROM tags WHERE parents_id='';";
return($self->{db}->cmd_firstcol($sql));
") 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 (@allused)=$self->used_tags();
+ my @allused=$self->used_tags();
my @used=grep { ref($_) ne "ARRAY"; } @allused;
my @used_with_vals=grep { ref($_) eq "ARRAY"; } @allused;
# print "tags(): USED: ", join(", ", @used), "\n";
# print "Trailing id: $tag\n";
}
my ($sqlclause, @joins)=(undef, ());
- ($sqlclause, @joins) = $tree->to_sql($tag) if($tree);
+ ($sqlclause, @joins) = $tree->to_sql() if($tree);
# print "SQL(" . scalar(@joins) .": $sqlclause\n";
my $sql="\tSELECT fxt1.files_id FROM tags t1";
my @crosses=();
sub to_sql
{
- my($self, $parent, @joins)=@_;
+ my($self, $not, @joins)=@_;
+ $not=0 unless(defined($not));
my @outjoins=();
# init
unless(@joins)
my $left=$self->left();
my $right=$self->right();
return ("", @outjoins) unless($left || $right);
- my ($leftstr, @leftjoins) = $self->node_to_sql($left, $parent, @joins);
+ my ($leftstr, @leftjoins) = $self->node_to_sql($left, $not, @joins);
push(@joins, @leftjoins);
push(@outjoins, @leftjoins);
my $op=$self->op();
}
elsif($op->{name} eq "NOT")
{
+ $not=1;
push(@joins, "LEFT");
push(@outjoins, "LEFT");
+ print("LEFT: ", $left->print(), "\n") if ($left);
+ print("RIGHT: ", $right->print(), "\n") if($right);
}
}
- my ($rightstr, @rightjoins) = $self->node_to_sql($right, $parent, @joins);
+ my ($rightstr, @rightjoins) = $self->node_to_sql($right, $not, @joins);
push(@outjoins, @rightjoins);
# print "LEFT (", scalar(@leftjoins), "): $leftstr\n";
# print "RIGHT (", scalar(@rightjoins), "): $rightstr\n";
my $str=$leftstr;
- $str .= (" " . $op->{name} . " ") if($op);
+ $str .= (" " . $op->{name} . " ") if($op && !$not);
$str .= $rightstr;
if($op || ($left && $right))
{
sub node_to_sql
{
- my($self, $node, $parent, @joins)=@_;
+ my($self, $node, $not, @joins)=@_;
return ("", ()) unless(defined($node));
- return $node->to_sql($parent, @joins) if(ref($node) eq "ID3FS::Path::Node");
+ return $node->to_sql($not, @joins) if(ref($node) eq "ID3FS::Path::Node");
my $sql;
my $cnt=scalar(@joins)+1;
if(defined($node->{parents_id}))
{
$sql= "(t" . scalar(@joins) . ".parents_id='$node->{parents_id}'";
- $sql .= " AND fxt" . scalar(@joins) . ".tags_id='" . $node->{id} . "')";
+ $sql .= " AND fxt" . scalar(@joins) . ".tags_id='" . $node->{id} . "'";
}
else
{
$sql= "(t" . scalar(@joins) .".parents_id=''";
- $sql .= " AND fxt" . scalar(@joins) . ".tags_id='" . $node->{id} . "')";
+ $sql .= " AND fxt" . scalar(@joins) . ".tags_id='" . $node->{id} . "'";
+ }
+ if($not)
+ {
+ $sql .= " AND fxt" . scalar(@joins) . ".files_id IS NULL";
}
+ $sql .= ")";
return ($sql, ());
}