") 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 @used=grep { ref($_) ne "ARRAY"; } @allused;
- my @used_with_vals=grep { ref($_) eq "ARRAY"; } @allused;
-# print "tags(): USED: ", join(", ", @used), "\n";
-# print "tags(): USED_WITH_VALS: ", join(", ", map { "[".$_->[0]. ", ".$_->[1]."]";} @used_with_vals), "\n";
- my @orclauses=();
my @andclauses=();
my $id=$self->trailing_tag_id();
- if($hasvals)
- {
-# print "HAS_VALUES\n";
- my @values=map { "'".$_->[1]."'"; } grep { $_->[0] == $id; } @used_with_vals;
- my $clause="(tags.parents_id='$id'";
- if(@values)
- {
- $clause .= " AND tags.id NOT IN (" . join(', ', @values) . ")";
- }
- $clause .= ")";
- push(@andclauses, $clause);
- }
- else
- {
-# print "HASNT VALUES\n";;
- if(@used)
- {
- push(@andclauses, "(NOT (tags.parents_id='' AND tags.id IN (" . join(', ', @used) . ")))");
- }
- for my $pair (@used_with_vals)
- {
- push(@andclauses, "(NOT (tags.parents_id='" . $pair->[0] . "' AND tags.id='" . $pair->[1] . "'))");
- }
- }
- my $parentclause= "(tags.parents_id='";
+ my $parentclause= "tags.parents_id='";
if($hasvals)
{
$parentclause .= $id;
{
$parentclause .= $parent;
}
- $parentclause .= "')";
+ $parentclause .= "'";
push(@andclauses, $parentclause);
- if(@orclauses)
+ my @used=$self->used_tags();
+ if(@used)
{
- push(@andclauses, '( ' . join(' OR ', @orclauses) . ' )');
+ push(@andclauses, "tags.id NOT IN (" . join(', ', @used) . ")");
}
if(@andclauses)
{
$sql .= "WHERE " . join(' AND ', @andclauses) . "\n";
}
+
$sql .= "GROUP BY tags.name;";
print "SQL(TAGS): $sql\n" if($self->{verbose});
my @tagnames=$self->{db}->cmd_firstcol($sql);
return $node->to_sql($hasvals, $not, @joins) if($node->type() eq "boolean");
my $sql;
my $cnt=scalar(@joins)+1;
- if(defined($node->{parents_id}))
- {
- $sql= "(t" . scalar(@joins) . ".parents_id='$node->{parents_id}'";
- $sql .= " AND t" . scalar(@joins) . ".id='" . $node->{id} . "'";
- }
- else
- {
- $sql= "(t" . scalar(@joins) .".parents_id=''";
- $sql .= " AND t" . scalar(@joins) . ".id='" . $node->{id} . "'";
- }
+ $sql .= "t" . scalar(@joins) . ".id='" . $node->{id} . "'";
if($not && !$hasvals)
{
$sql .= " AND fxt" . scalar(@joins) . ".files_id IS NULL";
}
- $sql .= ")";
return ($sql, ());
}
push(@used, $self->right()->used_tags()) if($self->right());
return(grep { defined; } @used);
}
- elsif($self->parents_id())
- {
- return([ $self->parents_id(), $self->id() ]);
- }
return $self->id();
}