[core] use || for SQL concatenation

MySQL supports this now?
This commit is contained in:
Shish 2024-06-19 23:32:43 +01:00 committed by Shish
parent ea700d5aa6
commit a59b9f706c
4 changed files with 5 additions and 13 deletions

View file

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

View file

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

View file

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

View file

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