Skip to content

Commit 4ea1817

Browse files
committed
Add fromQuery() logic to insertBatch()
1 parent 8b4ba58 commit 4ea1817

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
@@ -2130,12 +2130,28 @@ protected function formatValues(array $values): array
21302130
/**
21312131
* Compiles batch insert strings and runs the queries
21322132
*
2133-
* @param array|object|null $set a dataset
2133+
* @param array|BaseBuilder|RawSql|object|null $set a dataset
21342134
*
21352135
* @return false|int|string[] Number of rows inserted or FALSE on failure, SQL array when testMode
21362136
*/
21372137
public function insertBatch($set = null, ?bool $escape = null, int $batchSize = 100)
21382138
{
2139+
$this->fromQuery($set);
2140+
2141+
if (isset($this->QBOptions['fromQuery'])) {
2142+
$sql = $this->_insertBatch($this->QBFrom[0], $this->QBKeys, []);
2143+
2144+
if ($sql === '') {
2145+
return false; // @codeCoverageIgnore
2146+
}
2147+
2148+
$this->db->query($sql, null, false);
2149+
2150+
$this->resetWrite();
2151+
2152+
return $this->testMode ? $sql : $this->db->affectedRows();
2153+
}
2154+
21392155
if ($set !== null && $set !== []) {
21402156
$this->setData($set, $escape);
21412157
}

0 commit comments

Comments
 (0)