IdoQuery: Don't try to add a `HAVING` without group by rules

This commit is contained in:
Johannes Meyer 2022-02-11 12:04:05 +01:00
parent 44dc6fd8ee
commit a4d34e265f
1 changed files with 7 additions and 5 deletions

View File

@ -616,16 +616,18 @@ abstract class IdoQuery extends DbQuery
}
}
if ($and || $negate && ! $and) {
if ($and || $negate) {
// Having is only required for AND and != filters,
// e.g. hostgroup_name=(ping&linux), hostgroup_name!=ping, hostgroup_name!=(ping|linux)
$groups = $subQuery->getGroup();
$group = $groups[0];
$group = preg_replace('/(?<=^|\s)\w+(?=\.)/', 'sub_$0', $group);
if (! empty($groups)) {
$group = $groups[0];
$group = preg_replace('/(?<=^|\s)\w+(?=\.)/', 'sub_$0', $group);
$cnt = count($expr);
$cnt = count($expr);
$subQuery->select()->having("COUNT(DISTINCT $group) >= $cnt");
$subQuery->select()->having("COUNT(DISTINCT $group) >= $cnt");
}
}
$subQueryFilter->setColumn(preg_replace(