Skip to content

Commit

Permalink
DbConnection: Fix that unequal is handled as equal...
Browse files Browse the repository at this point in the history
refs #4814
  • Loading branch information
nilmerg committed Jun 13, 2022
1 parent 1bee2db commit ca4ec82
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions library/Icinga/Data/Db/DbConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,6 @@ protected function renderFilterExpression(Filter $filter)
$sign = $filter->getSign();
$value = $filter->getExpression();

$matchWildcard = $sign === '=' && ! $filter instanceof FilterEqual
|| $sign === '!=' && ! $filter instanceof FilterNotEqual;

if (is_array($value)) {
$comp = [];
$pattern = [];
Expand Down Expand Up @@ -582,13 +579,23 @@ protected function renderFilterExpression(Filter $filter)
}

return count($sql) === 1 ? $sql[0] : '(' . implode(" $operator ", $sql) . ')';
} elseif ($matchWildcard && $value !== null && strpos($value, '*') !== false) {
} elseif (
$sign === '='
&& ! $filter instanceof FilterEqual
&& $value !== null
&& strpos($value, '*') !== false
) {
if ($value === '*') {
return $column . ' IS NOT NULL';
}

return $column . ' LIKE ' . $this->dbAdapter->quote(preg_replace('~\*~', '%', $value));
} elseif ($matchWildcard && $value !== null && strpos($value, '*') !== false) {
} elseif (
$sign === '!='
&& ! $filter instanceof FilterNotEqual
&& $value !== null
&& strpos($value, '*') !== false
) {
if ($value === '*') {
return $column . ' IS NULL';
}
Expand Down

0 comments on commit ca4ec82

Please sign in to comment.