Merge pull request #682 from DanielOaks/develop+fix-sqlite-underscores

Fix SQLite underscore searching
This commit is contained in:
Shish 2019-09-15 16:36:30 +01:00 committed by GitHub
commit dbaf34f7c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -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)]
); );

View File

@ -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);