Merge pull request #4785 from Icinga/get-dbconnection-renderFilterExpression-up2date
Get `DbConnection::renderFilterExpression()` up to date
This commit is contained in:
commit
9c04776431
|
@ -545,22 +545,47 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||
$value = $filter->getExpression();
|
||||
|
||||
if (is_array($value)) {
|
||||
if ($sign === '=') {
|
||||
return $column . ' IN (' . $this->dbAdapter->quote($value) . ')';
|
||||
} elseif ($sign === '!=') {
|
||||
return sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $column, $this->dbAdapter->quote($value));
|
||||
$comp = [];
|
||||
$pattern = [];
|
||||
foreach ($value as $val) {
|
||||
if (strpos($val, '*') === false) {
|
||||
$comp[] = $val;
|
||||
} else {
|
||||
$pattern[] = $this->renderFilterExpression(Filter::expression($column, $sign, $val));
|
||||
}
|
||||
}
|
||||
|
||||
throw new ProgrammingError(
|
||||
'Unable to render array expressions with operators other than equal or not equal'
|
||||
);
|
||||
} elseif ($filter instanceof FilterMatch && strpos($value, '*') !== false) {
|
||||
$sql = $pattern;
|
||||
if ($sign === '=') {
|
||||
if (! empty($comp)) {
|
||||
$sql[] = $column . ' IN (' . $this->dbAdapter->quote($comp) . ')';
|
||||
}
|
||||
|
||||
$operator = 'OR';
|
||||
} elseif ($sign === '!=') {
|
||||
if (! empty($comp)) {
|
||||
$sql[] = sprintf(
|
||||
'(%1$s NOT IN (%2$s) OR %1$s IS NULL)',
|
||||
$column,
|
||||
$this->dbAdapter->quote($comp)
|
||||
);
|
||||
}
|
||||
|
||||
$operator = 'AND';
|
||||
} else {
|
||||
throw new ProgrammingError(
|
||||
'Unable to render array expressions with operators other than equal or not equal'
|
||||
);
|
||||
}
|
||||
|
||||
return count($sql) === 1 ? $sql[0] : '(' . implode(" $operator ", $sql) . ')';
|
||||
} elseif ($filter instanceof FilterMatch && $value !== null && strpos($value, '*') !== false) {
|
||||
if ($value === '*') {
|
||||
return $column . ' IS NOT NULL';
|
||||
}
|
||||
|
||||
return $column . ' LIKE ' . $this->dbAdapter->quote(preg_replace('~\*~', '%', $value));
|
||||
} elseif ($filter instanceof FilterMatchNot && strpos($value, '*') !== false) {
|
||||
} elseif ($filter instanceof FilterMatchNot && $value !== null && strpos($value, '*') !== false) {
|
||||
if ($value === '*') {
|
||||
return $column . ' IS NULL';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue