Skip to content

Commit 8f401de

Browse files
committed
Add fromQuery() logic to updateBatch()
1 parent 9e37fa5 commit 8f401de

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

system/Database/BaseBuilder.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,13 +2054,15 @@ public function onConstraint($set)
20542054
/**
20552055
* Sets data source as a query for insert/update/upsert
20562056
*
2057-
* @param BaseBuilder|string $query
2057+
* @param BaseBuilder|RawSql|string $query
20582058
*/
20592059
public function fromQuery($query): BaseBuilder
20602060
{
20612061
if (! empty($query)) {
20622062
if ($query instanceof BaseBuilder) {
20632063
$query = $query->getCompiledSelect();
2064+
} elseif ($query instanceof RawSql) {
2065+
$query = $query->__toString();
20642066
}
20652067

20662068
if (is_string($query)) {
@@ -2472,8 +2474,24 @@ protected function validateUpdate(): bool
24722474
*/
24732475
public function updateBatch($set = null, $constraints = null, int $batchSize = 100)
24742476
{
2477+
$this->fromQuery($set);
2478+
24752479
$this->onConstraint($constraints);
24762480

2481+
if (isset($this->QBOptions['fromQuery'])) {
2482+
$sql = $this->_updateBatch($this->QBFrom[0], $this->QBKeys, []);
2483+
2484+
if ($sql === '') {
2485+
return false; // @codeCoverageIgnore
2486+
}
2487+
2488+
$this->db->query($sql, null, false);
2489+
2490+
$this->resetWrite();
2491+
2492+
return $this->testMode ? $sql : $this->db->affectedRows();
2493+
}
2494+
24772495
if ($set !== null && $set !== []) {
24782496
$this->setData($set, true);
24792497
}

0 commit comments

Comments
 (0)