remove SCORE_STRNORM - everyone supports LOWER now

This commit is contained in:
Shish 2019-12-15 16:07:46 +00:00
parent 7b7febea55
commit d7a2ca9ddc
12 changed files with 22 additions and 26 deletions

View file

@ -6,7 +6,6 @@ abstract class SCORE
const BOOL_Y = "SCORE_BOOL_Y"; const BOOL_Y = "SCORE_BOOL_Y";
const BOOL_N = "SCORE_BOOL_N"; const BOOL_N = "SCORE_BOOL_N";
const BOOL = "SCORE_BOOL"; const BOOL = "SCORE_BOOL";
const STRNORM = "SCORE_STRNORM";
const ILIKE = "SCORE_ILIKE"; const ILIKE = "SCORE_ILIKE";
} }
@ -55,7 +54,6 @@ class MySQL extends DBEngine
$data = str_replace(SCORE::BOOL_Y, "'$this->BOOL_Y'", $data); $data = str_replace(SCORE::BOOL_Y, "'$this->BOOL_Y'", $data);
$data = str_replace(SCORE::BOOL_N, "'$this->BOOL_N'", $data); $data = str_replace(SCORE::BOOL_N, "'$this->BOOL_N'", $data);
$data = str_replace(SCORE::BOOL, "ENUM('Y', 'N')", $data); $data = str_replace(SCORE::BOOL, "ENUM('Y', 'N')", $data);
$data = str_replace(SCORE::STRNORM, "", $data);
$data = str_replace(SCORE::ILIKE, "LIKE", $data); $data = str_replace(SCORE::ILIKE, "LIKE", $data);
return $data; return $data;
} }
@ -101,7 +99,6 @@ class PostgreSQL extends DBEngine
$data = str_replace(SCORE::BOOL_Y, $this->BOOL_Y, $data); $data = str_replace(SCORE::BOOL_Y, $this->BOOL_Y, $data);
$data = str_replace(SCORE::BOOL_N, $this->BOOL_N, $data); $data = str_replace(SCORE::BOOL_N, $this->BOOL_N, $data);
$data = str_replace(SCORE::BOOL, "BOOL", $data); $data = str_replace(SCORE::BOOL, "BOOL", $data);
$data = str_replace(SCORE::STRNORM, "lower", $data);
$data = str_replace(SCORE::ILIKE, "ILIKE", $data); $data = str_replace(SCORE::ILIKE, "ILIKE", $data);
return $data; return $data;
} }
@ -196,7 +193,6 @@ class SQLite extends DBEngine
$data = str_replace(SCORE::BOOL_Y, "'$this->BOOL_Y'", $data); $data = str_replace(SCORE::BOOL_Y, "'$this->BOOL_Y'", $data);
$data = str_replace(SCORE::BOOL_N, "'$this->BOOL_N'", $data); $data = str_replace(SCORE::BOOL_N, "'$this->BOOL_N'", $data);
$data = str_replace(SCORE::BOOL, "CHAR(1)", $data); $data = str_replace(SCORE::BOOL, "CHAR(1)", $data);
$data = str_replace(SCORE::STRNORM, "lower", $data);
$data = str_replace(SCORE::ILIKE, "LIKE", $data); $data = str_replace(SCORE::ILIKE, "LIKE", $data);
return $data; return $data;
} }

View file

@ -306,7 +306,7 @@ class Image
} }
} elseif ($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) { } elseif ($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) {
$total = $database->get_one( $total = $database->get_one(
$database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), $database->scoreql_to_sql("SELECT count FROM tags WHERE LOWER(tag) = LOWER(:tag)"),
["tag"=>$tags[0]] ["tag"=>$tags[0]]
); );
} else { } else {
@ -720,7 +720,7 @@ class Image
$database->scoreql_to_sql(" $database->scoreql_to_sql("
SELECT id SELECT id
FROM tags FROM tags
WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag) WHERE LOWER(tag) = LOWER(:tag)
"), "),
["tag"=>$tag] ["tag"=>$tag]
); );
@ -733,7 +733,7 @@ class Image
$database->execute( $database->execute(
$database->scoreql_to_sql( $database->scoreql_to_sql(
"INSERT INTO image_tags(image_id, tag_id) "INSERT INTO image_tags(image_id, tag_id)
VALUES(:id, (SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)))" VALUES(:id, (SELECT id FROM tags WHERE LOWER(tag) = LOWER(:tag)))"
), ),
["id"=>$this->id, "tag"=>$tag] ["id"=>$this->id, "tag"=>$tag]
); );
@ -754,7 +754,7 @@ class Image
$database->scoreql_to_sql(" $database->scoreql_to_sql("
UPDATE tags UPDATE tags
SET count = count + 1 SET count = count + 1
WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag) WHERE LOWER(tag) = LOWER(:tag)
"), "),
["tag"=>$tag] ["tag"=>$tag]
); );
@ -957,7 +957,7 @@ class Image
$sq = " $sq = "
SELECT id SELECT id
FROM tags FROM tags
WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:tag) WHERE LOWER(tag) LIKE LOWER(:tag)
"; ";
if ($database->get_driver_name() === DatabaseDriver::SQLITE) { if ($database->get_driver_name() === DatabaseDriver::SQLITE) {
$sq .= "ESCAPE '\\'"; $sq .= "ESCAPE '\\'";

View file

@ -52,7 +52,7 @@ class Tag
$database->scoreql_to_sql(" $database->scoreql_to_sql("
SELECT newtag SELECT newtag
FROM aliases FROM aliases
WHERE SCORE_STRNORM(oldtag)=SCORE_STRNORM(:tag) WHERE LOWER(oldtag)=LOWER(:tag)
"), "),
["tag"=>$tag] ["tag"=>$tag]
); );

View file

@ -99,7 +99,7 @@ class User
public static function by_name(string $name): ?User public static function by_name(string $name): ?User
{ {
global $database; global $database;
$row = $database->get_row($database->scoreql_to_sql("SELECT * FROM users WHERE SCORE_STRNORM(name) = SCORE_STRNORM(:name)"), ["name"=>$name]); $row = $database->get_row($database->scoreql_to_sql("SELECT * FROM users WHERE LOWER(name) = LOWER(:name)"), ["name"=>$name]);
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }

View file

@ -138,7 +138,7 @@ class AdminPage extends Extension
{ {
global $database; global $database;
$database->execute($database->scoreql_to_sql( $database->execute($database->scoreql_to_sql(
"UPDATE tags SET tag=:tag1 WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag2)" "UPDATE tags SET tag=:tag1 WHERE LOWER(tag) = LOWER(:tag2)"
), ["tag1" => $_POST['tag'], "tag2" => $_POST['tag']]); ), ["tag1" => $_POST['tag'], "tag2" => $_POST['tag']]);
log_info("admin", "Fixed the case of ".html_escape($_POST['tag']), "Fixed case"); log_info("admin", "Fixed the case of ".html_escape($_POST['tag']), "Fixed case");
return true; return true;

View file

@ -48,8 +48,8 @@ class AutoComplete extends Extension
$database->scoreql_to_sql(" $database->scoreql_to_sql("
SELECT tag, count SELECT tag, count
FROM tags FROM tags
WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:search) WHERE LOWER(tag) LIKE LOWER(:search)
-- OR SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:cat_search) -- OR LOWER(tag) LIKE LOWER(:cat_search)
AND count > 0 AND count > 0
ORDER BY count DESC ORDER BY count DESC
$limitSQL"), $limitSQL"),

View file

@ -86,7 +86,7 @@ class DanbooruApi extends Extension
foreach ($namelist as $name) { foreach ($namelist as $name) {
$sqlresult = $database->get_all( $sqlresult = $database->get_all(
$database->scoreql_to_sql( $database->scoreql_to_sql(
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)" "SELECT id,tag,count FROM tags WHERE LOWER(tag) = LOWER(:tag)"
), ),
['tag'=>$name] ['tag'=>$name]
); );

View file

@ -114,7 +114,7 @@ class NotATag extends Extension
$input = validate_input(["d_tag"=>"string"]); $input = validate_input(["d_tag"=>"string"]);
$database->execute( $database->execute(
$database->scoreql_to_sql( $database->scoreql_to_sql(
"DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)" "DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)"
), ),
["tag"=>$input['d_tag']] ["tag"=>$input['d_tag']]
); );

View file

@ -579,10 +579,10 @@ class OuroborosAPI extends Extension
$database->scoreql_to_sql( $database->scoreql_to_sql(
" "
SELECT DISTINCT SELECT DISTINCT
id, SCORE_STRNORM(substr(tag, 1, 1)), count id, LOWER(substr(tag, 1, 1)), count
FROM tags FROM tags
WHERE count >= :tags_min WHERE count >= :tags_min
ORDER BY SCORE_STRNORM(substr(tag, 1, 1)) LIMIT :start, :max_items ORDER BY LOWER(substr(tag, 1, 1)) LIMIT :start, :max_items
" "
), ),
['tags_min' => $config->get_int(TagListConfig::TAGS_MIN), 'start' => $start, 'max_items' => $limit] ['tags_min' => $config->get_int(TagListConfig::TAGS_MIN), 'start' => $start, 'max_items' => $limit]

View file

@ -75,7 +75,7 @@ class TagCategories extends Extension
$count = $matches[3]; $count = $matches[3];
$types = $database->get_col( $types = $database->get_col(
$database->scoreql_to_sql('SELECT SCORE_STRNORM(category) FROM image_tag_categories') $database->scoreql_to_sql('SELECT LOWER(category) FROM image_tag_categories')
); );
if (in_array($type, $types)) { if (in_array($type, $types)) {
$event->add_querylet( $event->add_querylet(
@ -85,7 +85,7 @@ class TagCategories extends Extension
LEFT JOIN tags t ON it.tag_id = t.id LEFT JOIN tags t ON it.tag_id = t.id
WHERE images.id = it.image_id WHERE images.id = it.image_id
GROUP BY image_id GROUP BY image_id
HAVING SUM(CASE WHEN SCORE_STRNORM(t.tag) LIKE SCORE_STRNORM('$type:%') THEN 1 ELSE 0 END) $cmp $count HAVING SUM(CASE WHEN LOWER(t.tag) LIKE LOWER('$type:%') THEN 1 ELSE 0 END) $cmp $count
)")) )"))
); );
} }

View file

@ -66,7 +66,7 @@ class TagList extends Extension
$res = $database->get_col($database->scoreql_to_sql(" $res = $database->get_col($database->scoreql_to_sql("
SELECT tag SELECT tag
FROM tags FROM tags
WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:search) WHERE LOWER(tag) LIKE LOWER(:search)
AND count > 0 AND count > 0
$limitSQL $limitSQL
"), $SQLarr); "), $SQLarr);
@ -238,10 +238,10 @@ class TagList extends Extension
$tag_data = $database->get_col($database->scoreql_to_sql(" $tag_data = $database->get_col($database->scoreql_to_sql("
SELECT DISTINCT SELECT DISTINCT
SCORE_STRNORM(substr(tag, 1, 1)) LOWER(substr(tag, 1, 1))
FROM tags FROM tags
WHERE count >= :tags_min WHERE count >= :tags_min
ORDER BY SCORE_STRNORM(substr(tag, 1, 1)) ORDER BY LOWER(substr(tag, 1, 1))
"), ["tags_min"=>$tags_min]); "), ["tags_min"=>$tags_min]);
$html = "<span class='atoz'>"; $html = "<span class='atoz'>";
@ -284,7 +284,7 @@ class TagList extends Extension
FROM tags FROM tags
WHERE count >= :tags_min WHERE count >= :tags_min
AND tag SCORE_ILIKE :starts_with AND tag SCORE_ILIKE :starts_with
ORDER BY SCORE_STRNORM(tag) ORDER BY LOWER(tag)
"), ["tags_min"=>$tags_min, "tags_min2"=>$tags_min, "starts_with"=>$starts_with]); "), ["tags_min"=>$tags_min, "tags_min2"=>$tags_min, "starts_with"=>$starts_with]);
$html = ""; $html = "";
@ -327,7 +327,7 @@ class TagList extends Extension
FROM tags FROM tags
WHERE count >= :tags_min WHERE count >= :tags_min
AND tag SCORE_ILIKE :starts_with AND tag SCORE_ILIKE :starts_with
ORDER BY SCORE_STRNORM(tag) ORDER BY LOWER(tag)
"), ["tags_min"=>$tags_min, "starts_with"=>$starts_with]); "), ["tags_min"=>$tags_min, "starts_with"=>$starts_with]);
$html = ""; $html = "";

View file

@ -231,7 +231,7 @@ class Wiki extends Extension
$database->scoreql_to_sql(" $database->scoreql_to_sql("
SELECT * SELECT *
FROM wiki_pages FROM wiki_pages
WHERE SCORE_STRNORM(title) LIKE SCORE_STRNORM(:title) WHERE LOWER(title) LIKE LOWER(:title)
ORDER BY revision DESC"), ORDER BY revision DESC"),
["title"=>$title] ["title"=>$title]
); );