Create better newsgroup lists for SQL clause.
Build a 'IN(...)' list for single newsgroup names without wildcards. Create SQL clause with a mix of wildcards and wildcard-less group names. More code for a better query ... Fixes #37. Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
parent
d28168419e
commit
10459ac8c7
40
NewsStats.pm
40
NewsStats.pm
|
@ -576,14 +576,46 @@ sub SQLGroupList {
|
||||||
$Newsgroups =~ s/\*/%/g;
|
$Newsgroups =~ s/\*/%/g;
|
||||||
# just one newsgroup?
|
# just one newsgroup?
|
||||||
return (SQLGroupWildcard($Newsgroups),$Newsgroups) if $Newsgroups !~ /:/;
|
return (SQLGroupWildcard($Newsgroups),$Newsgroups) if $Newsgroups !~ /:/;
|
||||||
|
my ($SQL,@WildcardGroups,@NoWildcardGroups);
|
||||||
# list of newsgroups separated by ':'
|
# list of newsgroups separated by ':'
|
||||||
my $SQL = '(';
|
|
||||||
my @GroupList = split /:/, $Newsgroups;
|
my @GroupList = split /:/, $Newsgroups;
|
||||||
foreach (@GroupList) {
|
foreach (@GroupList) {
|
||||||
$SQL .= ' OR ' if $SQL gt '(';
|
if ($_ !~ /%/) {
|
||||||
$SQL .= SQLGroupWildcard($_);
|
# add to list of newsgroup names WITHOUT wildcard
|
||||||
|
push (@NoWildcardGroups,$_);
|
||||||
|
} else {
|
||||||
|
# add to list of newsgroup names WITH wildcard
|
||||||
|
push (@WildcardGroups,$_);
|
||||||
|
# add wildcard to SQL clause
|
||||||
|
# 'OR' if SQL clause is not empty
|
||||||
|
$SQL .= ' OR ' if $SQL;
|
||||||
|
$SQL .= 'newsgroup LIKE ?'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
$SQL .= ')';
|
if (scalar(@NoWildcardGroups)) {
|
||||||
|
# add 'OR' if SQL clause is not empty
|
||||||
|
$SQL .= ' OR ' if $SQL;
|
||||||
|
if (scalar(@NoWildcardGroups) < 2) {
|
||||||
|
# special case: just one newsgroup without wildcard
|
||||||
|
$SQL .= 'newsgroup = ?';
|
||||||
|
} else {
|
||||||
|
# create list of newsgroups to include: 'newsgroup IN (...)'
|
||||||
|
$SQL .= 'newsgroup IN (';
|
||||||
|
my $SQLin;
|
||||||
|
foreach (@NoWildcardGroups) {
|
||||||
|
$SQLin .= ',' if $SQLin;
|
||||||
|
$SQLin .= '?';
|
||||||
|
}
|
||||||
|
# add list to SQL clause
|
||||||
|
$SQL .= $SQLin .= ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# add brackets '()' to SQL clause as needed (more than one wildcard group)
|
||||||
|
if (scalar(@WildcardGroups)) {
|
||||||
|
$SQL = '(' . $SQL .')';
|
||||||
|
}
|
||||||
|
# rebuild @GroupList in (now) correct order
|
||||||
|
@GroupList = (@WildcardGroups,@NoWildcardGroups);
|
||||||
return ($SQL,@GroupList);
|
return ($SQL,@GroupList);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue