From efac91598cc2a55c86c574237ab03c9cec92fa1f Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 2 Feb 2010 02:13:45 +0000 Subject: [PATCH] SCORE_STRNORM = lowercase-if-necessary-for-comparison --- core/database.class.php | 3 +++ core/imageboard.pack.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 7ea8dabc..2091b27e 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -77,6 +77,7 @@ class MySQL extends DBEngine { $data = str_replace("SCORE_BOOL", "ENUM('Y', 'N')", $data); $data = str_replace("SCORE_DATETIME", "DATETIME", $data); $data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data); + $data = str_replace("SCORE_STRNORM", "", $data); return $data; } @@ -97,6 +98,7 @@ class PostgreSQL extends DBEngine { $data = str_replace("SCORE_BOOL", "BOOL", $data); $data = str_replace("SCORE_DATETIME", "TIMESTAMP", $data); $data = str_replace("SCORE_NOW", "current_time", $data); + $data = str_replace("SCORE_STRNORM", "lower", $data); return $data; } @@ -142,6 +144,7 @@ class SQLite extends DBEngine { $data = str_replace("SCORE_BOOL_N", "'N'", $data); $data = str_replace("SCORE_BOOL", "CHAR(1)", $data); $data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data); + $data = str_replace("SCORE_STRNORM", "", $data); $cols = array(); $extras = ""; foreach(explode(",", $data) as $bit) { diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 120c3043..88b677d6 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -394,13 +394,11 @@ class Image { // insert each new tags foreach($tags as $tag) { - if($database->engine->name == "pgsql") { - $query = "SELECT id FROM tags WHERE lower(tag) = lower(?)"; - } - else { - $query = "SELECT id FROM tags WHERE tag = ?"; - } - $id = $database->db->GetOne($query, array($tag)); + $id = $database->db->GetOne( + $database->engine->scoreql_to_sql( + "SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)" + ), + array($tag)); if(empty($id)) { // a new tag $database->execute( @@ -418,7 +416,9 @@ class Image { array($this->id, $id)); } $database->execute( - "UPDATE tags SET count = count + 1 WHERE tag = ?", + $database->engine->scoreql_to_sql( + "UPDATE tags SET count = count + 1 WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)" + ), array($tag)); }