From 88da3588e5d38a6f40a5df7490547a8f3df6819f Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 26 Jan 2025 13:50:12 +0100 Subject: [PATCH] Compat/SQL * make ON DUPLICATE KEY UPDATE queries compatible with both MySQL8 and MariaDB by providing update values from php --- includes/types/profile.class.php | 4 ++-- includes/utilities.php | 4 ++-- setup/tools/sqlgen/questsstartend.ss.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/types/profile.class.php b/includes/types/profile.class.php index a89214ad..e522810c 100644 --- a/includes/types/profile.class.php +++ b/includes/types/profile.class.php @@ -707,8 +707,8 @@ class RemoteProfileList extends ProfileList // basic char data (enough for tooltips) if ($baseData) { - foreach (Util::createSqlBatchInsert($baseData) as $ins) - DB::Aowow()->query('INSERT INTO ?_profiler_profiles (?#) VALUES '.$ins.' AS newP(`r`, `rg`, `na`, `itr`, `ra`, `cl`, `lvl`, `ge`, `g`, `gr`, `cf`) ON DUPLICATE KEY UPDATE `name` = newP.`na`, `renameItr` = newP.`itr`', array_keys(reset($baseData))); + foreach ($baseData as $ins) + DB::Aowow()->query('INSERT INTO ?_profiler_profiles (?#) VALUES (?a) ON DUPLICATE KEY UPDATE `name` = ?, `renameItr` = ?d', array_keys($ins), array_values($ins), $ins['name'], $ins['renameItr']); // merge back local ids $localIds = DB::Aowow()->select( diff --git a/includes/utilities.php b/includes/utilities.php index f6eff9e3..2467de88 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -1263,7 +1263,7 @@ abstract class Util return $json; } - public static function createSqlBatchInsert(array $data) + public static function createSqlBatchInsert(array $data) : array { $nRows = 100; $nItems = count(reset($data)); @@ -1278,7 +1278,7 @@ abstract class Util if (count($d) != $nItems) return []; - $d = array_map(function ($x) { return $x === null ? 'NULL' : DB::Aowow()->escape($x); }, $d); + $d = array_map(fn($x) => $x === null ? 'NULL' : DB::Aowow()->escape($x), $d); $buff[] = implode(',', $d); diff --git a/setup/tools/sqlgen/questsstartend.ss.php b/setup/tools/sqlgen/questsstartend.ss.php index 23119f36..f48a42d2 100644 --- a/setup/tools/sqlgen/questsstartend.ss.php +++ b/setup/tools/sqlgen/questsstartend.ss.php @@ -37,7 +37,7 @@ CLISetup::registerSetup("sql", new class extends SetupScript $data = DB::World()->select($q); foreach ($data as $d) - DB::Aowow()->query('INSERT INTO ?_quests_startend (?#) VALUES (?a) AS newQSE(`t`, `ti`, `qi`, `m`, `ei`) ON DUPLICATE KEY UPDATE `method` = `method` | newQSE.`m`, `eventId` = IF(`eventId` = 0, newQSE.`ei`, `eventId`)', array_keys($d), array_values($d)); + DB::Aowow()->query('INSERT INTO ?_quests_startend (?#) VALUES (?a) ON DUPLICATE KEY UPDATE `method` = `method` | ?d, `eventId` = IF(`eventId` = 0, ?d, `eventId`)', array_keys($d), array_values($d), $d['method'], $d['eventId']); } // update quests without start as unavailable