Fix SQLite underscore searching (#619)

This commit is contained in:
Daniel Oaks 2019-09-14 13:45:28 +10:00
parent ba20d8d5af
commit a1c276c840
2 changed files with 13 additions and 5 deletions

View file

@ -944,12 +944,16 @@ class Image
$negative_tag_id_array = [];
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(
$database->scoreql_to_sql("
SELECT id
FROM tags
WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:tag)
"),
$database->scoreql_to_sql($sq),
["tag" => Tag::sqlify($tq->tag)]
);

View file

@ -103,6 +103,10 @@ class Tag
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);