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

View File

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