Fix SQLite underscore searching (#619)
This commit is contained in:
parent
ba20d8d5af
commit
a1c276c840
2 changed files with 13 additions and 5 deletions
|
@ -944,12 +944,16 @@ class Image
|
||||||
$negative_tag_id_array = [];
|
$negative_tag_id_array = [];
|
||||||
|
|
||||||
foreach ($tag_conditions as $tq) {
|
foreach ($tag_conditions as $tq) {
|
||||||
|
$sq = "
|
||||||
|
SELECT id
|
||||||
|
FROM tags
|
||||||
|
WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:tag)
|
||||||
|
";
|
||||||
|
if ($database->get_driver_name() === DatabaseDriver::SQLITE) {
|
||||||
|
$sq .= "ESCAPE '\\'";
|
||||||
|
}
|
||||||
$tag_ids = $database->get_col(
|
$tag_ids = $database->get_col(
|
||||||
$database->scoreql_to_sql("
|
$database->scoreql_to_sql($sq),
|
||||||
SELECT id
|
|
||||||
FROM tags
|
|
||||||
WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:tag)
|
|
||||||
"),
|
|
||||||
["tag" => Tag::sqlify($tq->tag)]
|
["tag" => Tag::sqlify($tq->tag)]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,10 @@ class Tag
|
||||||
|
|
||||||
public static function sqlify(string $term): string
|
public static function sqlify(string $term): string
|
||||||
{
|
{
|
||||||
|
global $database;
|
||||||
|
if ($database->get_driver_name() === DatabaseDriver::SQLITE) {
|
||||||
|
$term = str_replace('\\', '\\\\', $term);
|
||||||
|
}
|
||||||
$term = str_replace('_', '\_', $term);
|
$term = str_replace('_', '\_', $term);
|
||||||
$term = str_replace('%', '\%', $term);
|
$term = str_replace('%', '\%', $term);
|
||||||
$term = str_replace('*', '%', $term);
|
$term = str_replace('*', '%', $term);
|
||||||
|
|
Reference in a new issue