# fail if more than one newsgroup is combined with 'dumpgroup' type
die("$MySelf: E: You cannot combine newsgroup lists (-n) with more than one group with '-o dumpgroup'!\n")if($Options{'o'}eq'dumpgroup'anddefined($Options{'n'})and$Options{'n'}=~ /:|\*/);
# do query: get number of postings per group from groups table for given months and newsgroups
$DBQuery=$DBHandle->prepare(sprintf("SELECT month,newsgroup,postings FROM %s.%s WHERE %s ORDER BY month,%s",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$WhereClause,$OrderClause));
}elsif($Options{'b'}){
# set sorting order (-i)
if($Options{'i'}){
$OrderClause='postings';
}else{
$OrderClause='postings DESC';
};
# push LIMIT to GroupList to match number of binding vars
push@GroupList,$Options{'b'};
# do query: get sum of postings per group from groups table for given months and newsgroups with LIMIT
$DBQuery=$DBHandle->prepare(sprintf("SELECT newsgroup,SUM(postings) AS postings FROM %s.%s WHERE %s GROUP BY newsgroup ORDER BY %s,newsgroup LIMIT ?",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$WhereClause,$OrderClause));
}else{# -l
# set sorting order (-i)
if($Options{'i'}){
$OrderClause='<';
}else{
$OrderClause='>';
};
# push level and $StartMonth,$EndMonth - again - to GroupList to match number of binding vars
push@GroupList,$Options{'l'};
push@GroupList,$StartMonth,$EndMonth;
# do query: get number of postings per group from groups table for given months and
$DBQuery=$DBHandle->prepare(sprintf("SELECT month,newsgroup,postings FROM %s.%s WHERE newsgroup IN (SELECT newsgroup FROM %s.%s WHERE %s GROUP BY newsgroup HAVING MAX(postings) %s ?) AND %s ORDER BY newsgroup,month",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$WhereClause,$OrderClause,$WhereClause));
};
# execute query
$DBQuery->execute($StartMonth,$EndMonth,@GroupList)ordiesprintf("$MySelf: E: Can't get groups data for %s to %s from %s.%s: %s\n",$StartMonth,$EndMonth,$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$DBI::errstr);
# output result
printf("----- Report from %s to %s\n",$StartMonth,$EndMonth)if$Options{'c'}and($Options{'m'}or$Options{'p'});