Fixed API equals/not equals filter comparison (fixes #1182)

This commit is contained in:
Bernd Bestel
2020-12-16 21:52:24 +01:00
parent 13b18ef410
commit bb6ef5511d

View File

@@ -93,17 +93,18 @@ class BaseApiController extends BaseController
throw new \Exception('Invalid query'); throw new \Exception('Invalid query');
} }
$sqlOrNull = '';
if (strtolower($matches['value']) == 'null') if (strtolower($matches['value']) == 'null')
{ {
$matches['value'] = ''; $sqlOrNull = ' OR ' . $matches['field'] . ' IS NULL';
} }
switch ($matches['op']) { switch ($matches['op']) {
case '=': case '=':
$data = $data->where('IFNULL(' . $matches['field'] . ', \'\') = ?', $matches['value']); $data = $data->where($matches['field'] . ' = ?' . $sqlOrNull, $matches['value']);
break; break;
case '!=': case '!=':
$data = $data->where('IFNULL(' . $matches['field'] . ', \'\') != ?', $matches['value']); $data = $data->where($matches['field'] . ' != ?' . $sqlOrNull, $matches['value']);
break; break;
case '~': case '~':
$data = $data->where($matches['field'] . ' LIKE ?', '%' . $matches['value'] . '%'); $data = $data->where($matches['field'] . ' LIKE ?', '%' . $matches['value'] . '%');