Support wildcard filters in chains (#3903)

This commit is contained in:
Eric Lippmann 2019-08-12 13:41:38 +02:00 committed by Johannes Meyer
parent 2ca3ffcb60
commit 31d3153d2b
1 changed files with 21 additions and 3 deletions

View File

@ -298,13 +298,31 @@ class DbQuery extends SimpleQuery
}
if (is_array($expression)) {
$comp = [];
$pattern = [];
foreach ($expression as $value) {
if (strpos($value, '*') === false) {
$comp[] = $value;
} else {
$pattern[] = $this->whereToSql($col, $sign, $value);
}
}
$sql = $pattern;
if ($sign === '=') {
return $col . ' IN (' . $this->escapeForSql($expression) . ')';
if (! empty($comp)) {
$sql[] = $col . ' IN (' . $this->escapeForSql($comp) . ')';
}
} elseif ($sign === '!=') {
return sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $col, $this->escapeForSql($expression));
if (! empty($comp)) {
$sql[] = sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $col, $this->escapeForSql($comp));
}
} else {
throw new QueryException(
'Unable to render array expressions with operators other than equal or not equal'
);
}
throw new QueryException('Unable to render array expressions with operators other than equal or not equal');
return '(' . implode(' OR ', $sql) . ')';
} elseif ($sign === '=' && strpos($expression, '*') !== false) {
if ($expression === '*') {
return new Zend_Db_Expr('TRUE');