Skip to content

Commit 3de5b5b

Browse files
committed
Fixes
1 parent 8ec1fa5 commit 3de5b5b

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

system/Database/BaseBuilder.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,13 +2225,11 @@ protected function _updateBatch(string $table, array $values, string $index): st
22252225
$sql .= implode(
22262226
" UNION ALL\n",
22272227
array_map(
2228-
static function ($value) use ($keys) {
2229-
return 'SELECT ' . implode(', ', array_map(
2230-
static fn ($key, $index) => $index . ' ' . $key,
2231-
$keys,
2232-
$value
2233-
));
2234-
},
2228+
static fn($value) => 'SELECT ' . implode(', ', array_map(
2229+
static fn ($key, $index) => $index . ' ' . $key,
2230+
$keys,
2231+
$value
2232+
)),
22352233
$values
22362234
)
22372235
) . "\n";

system/Database/MySQLi/Builder.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ protected function _updateBatch(string $table, array $values, string $index): st
7575
$sql .= implode(
7676
" UNION ALL\n",
7777
array_map(
78-
static function ($value) use ($keys) {
79-
return 'SELECT ' . implode(', ', array_map(
80-
static fn ($key, $index) => $index . ' ' . $key,
81-
$keys,
82-
$value
83-
));
84-
},
78+
static fn($value) => 'SELECT ' . implode(', ', array_map(
79+
static fn ($key, $index) => $index . ' ' . $key,
80+
$keys,
81+
$value
82+
)),
8583
$values
8684
)
8785
) . "\n";

system/Database/OCI8/Builder.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,11 @@ protected function _updateBatch(string $table, array $values, string $index): st
250250
$sql .= implode(
251251
" UNION ALL\n",
252252
array_map(
253-
static function ($value) use ($keys) {
254-
return 'SELECT ' . implode(', ', array_map(
255-
static fn ($key, $index) => $index . ' ' . $key,
256-
$keys,
257-
$value
258-
)) . ' FROM DUAL';
253+
static fn($value) => 'SELECT ' . implode(', ', array_map(
254+
static fn ($key, $index) => $index . ' ' . $key,
255+
$keys,
256+
$value
257+
)) . ' FROM DUAL',
259258
},
260259
$values
261260
)

system/Database/SQLite3/Builder.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,39 @@ protected function _truncate(string $table): string
7070
{
7171
return 'DELETE FROM ' . $table;
7272
}
73+
74+
/**
75+
* Generates a platform-specific batch update string from the supplied data
76+
*/
77+
protected function _updateBatch(string $table, array $values, string $index): string
78+
{
79+
if ((float) $this->db->getVersion() >= 3.33) {
80+
return parent::_updateBatch($table, $values, $index);
81+
}
82+
83+
$ids = [];
84+
$final = [];
85+
86+
foreach ($values as $val) {
87+
$ids[] = $val[$index];
88+
89+
foreach (array_keys($val) as $field) {
90+
if ($field !== $index) {
91+
$final[$field][] = 'WHEN ' . $index . ' = ' . $val[$index] . ' THEN ' . $val[$field];
92+
}
93+
}
94+
}
95+
96+
$cases = '';
97+
98+
foreach ($final as $k => $v) {
99+
$cases .= $k . " = CASE \n"
100+
. implode("\n", $v) . "\n"
101+
. 'ELSE ' . $k . ' END, ';
102+
}
103+
104+
$this->where($index . ' IN(' . implode(',', $ids) . ')', null, false);
105+
106+
return 'UPDATE ' . $this->compileIgnore('update') . $table . ' SET ' . substr($cases, 0, -2) . $this->compileWhereHaving('QBWhere');
107+
}
73108
}

tests/system/Database/Builder/UpdateTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ public function testUpdateBatch()
231231
$query = $this->db->getLastQuery();
232232
$this->assertInstanceOf(MockQuery::class, $query);
233233

234-
$space = ' ';
235-
236234
$expected = <<<'EOF'
237235
UPDATE "jobs"
238236
SET

0 commit comments

Comments
 (0)