Fix WHERE ... LIKE ... for SQLite

https://github.com/forkbb/forkbb/pull/10
This commit is contained in:
Visman 2021-12-18 00:51:59 +07:00
parent 2b546af3b9
commit a71cb56039
3 changed files with 6 additions and 6 deletions

View file

@ -54,8 +54,8 @@ class Filter extends Method
if (false !== \strpos($rule[1], '*')) {
// кроме * есть другие символы
if ('' != \trim($rule[1], '*')) {
$where[] = "b.{$field} LIKE ?{$fields[$field]}";
$vars[] = \str_replace(['%', '*', '_'], ['\\%', '%', '\\_'], $rule[1]);
$where[] = "b.{$field} LIKE ?{$fields[$field]} ESCAPE '#'";
$vars[] = \str_replace(['#', '%', '_', '*'], ['##', '#%', '#_', '%'], $rule[1]);
}
break;
}

View file

@ -223,8 +223,8 @@ class Execute extends Method
//???? что делать с подчеркиванием в именах?
if ('*' !== $v->author) {
$usePIdx = true;
$vars[':author'] = \str_replace(['*', '?'], ['%', '_'], $v->author);
$whereIdx[] = 'p.poster LIKE ?s:author';
$vars[':author'] = \str_replace(['#', '_', '*', '?'], ['##', '#_', '%', '_'], $v->author);
$whereIdx[] = 'p.poster LIKE ?s:author ESCAPE \'#\'';
}
$this->model->showAs = $v->show_as;

View file

@ -54,8 +54,8 @@ class Filter extends Action
if (false !== \strpos($rule[1], '*')) {
// кроме * есть другие символы
if ('' != \trim($rule[1], '*')) {
$where[] = "u.{$field} LIKE ?{$fields[$field]}";
$vars[] = \str_replace(['%', '*', '_'], ['\\%', '%', '\\_'], $rule[1]);
$where[] = "u.{$field} LIKE ?{$fields[$field]} ESCAPE '#'";
$vars[] = \str_replace(['#', '%', '_', '*'], ['##', '#%', '#_', '%'], $rule[1]);
}
break;
}