Skip to content

Commit afede47

Browse files
committed
Add fromQuery() logic to insertBatch()
1 parent bbe4331 commit afede47

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

system/Database/BaseBuilder.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2128,12 +2128,28 @@ protected function formatValues(array $values): array
21282128
/**
21292129
* Compiles batch insert strings and runs the queries
21302130
*
2131-
* @param array|object|null $set a dataset
2131+
* @param array|BaseBuilder|RawSql|object|null $set a dataset
21322132
*
21332133
* @return false|int|string[] Number of rows inserted or FALSE on failure, SQL array when testMode
21342134
*/
21352135
public function insertBatch($set = null, ?bool $escape = null, int $batchSize = 100)
21362136
{
2137+
$this->fromQuery($set);
2138+
2139+
if (isset($this->QBOptions['fromQuery'])) {
2140+
$sql = $this->_insertBatch($this->QBFrom[0], $this->QBKeys, []);
2141+
2142+
if ($sql === '') {
2143+
return false; // @codeCoverageIgnore
2144+
}
2145+
2146+
$this->db->query($sql, null, false);
2147+
2148+
$this->resetWrite();
2149+
2150+
return $this->testMode ? $sql : $this->db->affectedRows();
2151+
}
2152+
21372153
if ($set !== null && $set !== []) {
21382154
$this->setData($set, $escape);
21392155
}

0 commit comments

Comments
 (0)