#13264 added regex in sql

This commit is contained in:
Daniel Cebrian 2024-04-23 16:56:28 +02:00
parent 7a78283eed
commit 64013c0416
2 changed files with 36 additions and 41 deletions

View File

@ -1155,7 +1155,7 @@ function events_get_all(
}
// Free search.
if (empty($filter['search']) === false && (bool) $filter['regex'] === false) {
if (empty($filter['search']) === false) {
if (isset($config['dbconnection']->server_version) === true
&& $config['dbconnection']->server_version > 50600
) {
@ -1185,23 +1185,39 @@ function events_get_all(
$array_search[] = 'lower(ta.alias)';
}
// Disregard repeated whitespaces when searching.
$collapsed_spaces_search = preg_replace('/( )+/', ' ', $filter['search']);
if ((bool) $filter['regex'] === true) {
$sql_search = ' AND (';
foreach ($array_search as $key => $field) {
$sql_search .= sprintf(
'%s %s %s REGEXP "%s" ',
($key === 0) ? '' : $nexo,
$field,
$not_search,
io_safe_output($filter['search'])
);
$sql_search .= ' ';
}
$sql_search = ' AND (';
foreach ($array_search as $key => $field) {
$sql_search .= sprintf(
'%s LOWER(REGEXP_REPLACE(%s, "( )+", " ")) %s like LOWER("%%%s%%")',
($key === 0) ? '' : $nexo,
$field,
$not_search,
$collapsed_spaces_search
);
$sql_search .= ' ';
$sql_search .= ' )';
} else {
// Disregard repeated whitespaces when searching.
$collapsed_spaces_search = preg_replace('/( )+/', ' ', $filter['search']);
$sql_search = ' AND (';
foreach ($array_search as $key => $field) {
$sql_search .= sprintf(
'%s LOWER(REGEXP_REPLACE(%s, "( )+", " ")) %s like LOWER("%%%s%%")',
($key === 0) ? '' : $nexo,
$field,
$not_search,
$collapsed_spaces_search
);
$sql_search .= ' ';
}
$sql_search .= ' )';
}
$sql_search .= ' )';
$sql_filters[] = $sql_search;
}

View File

@ -1249,27 +1249,7 @@ if (is_ajax() === true) {
}
}
$regex_validation = false;
if (empty($tmp) === false && $regex !== '') {
foreach (json_decode(json_encode($tmp), true) as $key => $field) {
if ($key === 'b64') {
continue;
}
$field = strip_tags($field);
if (preg_match('/'.io_safe_output($regex).'/', $field)) {
$regex_validation = true;
}
}
if ($regex_validation === true) {
$carry[] = $tmp;
}
} else {
$carry[] = $tmp;
}
$carry[] = $tmp;
return $carry;
}
);
@ -1289,11 +1269,10 @@ if (is_ajax() === true) {
// RecordsTotal && recordsfiltered resultados totales.
echo json_encode(
[
'data' => ($data ?? []),
'buffers' => $buffers,
'recordsTotal' => $count,
'recordsFiltered' => $count,
'showAlwaysPagination' => (empty($regex) === false) ? true : false,
'data' => ($data ?? []),
'buffers' => $buffers,
'recordsTotal' => $count,
'recordsFiltered' => $count,
]
);
} catch (Exception $e) {