From a59b9f706ce301008571e20abaec833c978b414c Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 19 Jun 2024 23:32:43 +0100 Subject: [PATCH] [core] use || for SQL concatenation MySQL supports this now? --- core/database.php | 2 +- core/dbengine.php | 5 ----- core/user.php | 9 +++------ ext/tagger_xml/main.php | 2 +- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/core/database.php b/core/database.php index acfdd904..cbb2eeb7 100644 --- a/core/database.php +++ b/core/database.php @@ -452,6 +452,6 @@ class Database } // As fallback, use MD5 as a DRBG. - return "MD5(CONCAT($seed, CONCAT('+', $id_column)))"; + return "MD5($seed || '+' || $id_column)"; } } diff --git a/core/dbengine.php b/core/dbengine.php index 6376bd5b..c84355a8 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -154,10 +154,6 @@ function _md5(string $a): string { return md5($a); } -function _concat(string $a, string $b): string -{ - return $a . $b; -} function _lower(string $a): string { return strtolower($a); @@ -185,7 +181,6 @@ class SQLite extends DBEngine $db->sqliteCreateFunction('log', 'Shimmie2\_log'); $db->sqliteCreateFunction('isnull', 'Shimmie2\_isnull', 1); $db->sqliteCreateFunction('md5', 'Shimmie2\_md5', 1); - $db->sqliteCreateFunction('concat', 'Shimmie2\_concat', 2); $db->sqliteCreateFunction('lower', 'Shimmie2\_lower', 1); $db->sqliteCreateFunction('rand', 'Shimmie2\_rand', 0); $db->sqliteCreateFunction('ln', 'Shimmie2\_ln', 1); diff --git a/core/user.php b/core/user.php index d415b48a..98b98d5b 100644 --- a/core/user.php +++ b/core/user.php @@ -85,12 +85,9 @@ class User global $cache, $config, $database; $row = $cache->get("user-session:$name-$session"); if (is_null($row)) { - if ($database->get_driver_id() === DatabaseDriverID::MYSQL) { - $query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess"; - } else { - $query = "SELECT * FROM users WHERE name = :name AND md5(pass || :ip) = :sess"; - } - $row = $database->get_row($query, ["name" => $name, "ip" => get_session_ip($config), "sess" => $session]); + $args = ["name" => $name, "ip" => get_session_ip($config), "sess" => $session]; + $query = "SELECT * FROM users WHERE name = :name AND md5(pass || :ip) = :sess"; + $row = $database->get_row($query, $args); $cache->set("user-session:$name-$session", $row, 600); } return is_null($row) ? null : new User($row); diff --git a/ext/tagger_xml/main.php b/ext/tagger_xml/main.php index c9f39f24..312e7cf7 100644 --- a/ext/tagger_xml/main.php +++ b/ext/tagger_xml/main.php @@ -53,7 +53,7 @@ class TaggerXML extends Extension ]; // Match - $match = "concat(:p, tag) LIKE :sq"; + $match = "(:p || tag) LIKE :sq"; // Exclude // $exclude = $event->get_arg('exclude')? "AND NOT IN ".$this->image_tags($event->get_arg('exclude')) : null;