mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Compat/SQL
* make ON DUPLICATE KEY UPDATE queries compatible with both MySQL8 and MariaDB by providing update values from php
This commit is contained in:
@@ -707,8 +707,8 @@ class RemoteProfileList extends ProfileList
|
|||||||
// basic char data (enough for tooltips)
|
// basic char data (enough for tooltips)
|
||||||
if ($baseData)
|
if ($baseData)
|
||||||
{
|
{
|
||||||
foreach (Util::createSqlBatchInsert($baseData) as $ins)
|
foreach ($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)));
|
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
|
// merge back local ids
|
||||||
$localIds = DB::Aowow()->select(
|
$localIds = DB::Aowow()->select(
|
||||||
|
|||||||
@@ -1263,7 +1263,7 @@ abstract class Util
|
|||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createSqlBatchInsert(array $data)
|
public static function createSqlBatchInsert(array $data) : array
|
||||||
{
|
{
|
||||||
$nRows = 100;
|
$nRows = 100;
|
||||||
$nItems = count(reset($data));
|
$nItems = count(reset($data));
|
||||||
@@ -1278,7 +1278,7 @@ abstract class Util
|
|||||||
if (count($d) != $nItems)
|
if (count($d) != $nItems)
|
||||||
return [];
|
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);
|
$buff[] = implode(',', $d);
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ CLISetup::registerSetup("sql", new class extends SetupScript
|
|||||||
|
|
||||||
$data = DB::World()->select($q);
|
$data = DB::World()->select($q);
|
||||||
foreach ($data as $d)
|
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
|
// update quests without start as unavailable
|
||||||
|
|||||||
Reference in New Issue
Block a user