Skip to content

Commit 0f3088c

Browse files
committed
fix: make the return type of insertBatch() the same as updateBatch()
1 parent 10b3de2 commit 0f3088c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
15901590
*
15911591
* @throws DatabaseException
15921592
*
1593-
* @return false|int Number of rows inserted or FALSE on failure
1593+
* @return false|int|string[] Number of rows inserted or FALSE on failure, SQL array when testMode
15941594
*/
15951595
public function insertBatch(?array $set = null, ?bool $escape = null, int $batchSize = 100)
15961596
{
@@ -1617,12 +1617,13 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
16171617
$table = $this->QBFrom[0];
16181618

16191619
$affectedRows = 0;
1620+
$savedSQL = [];
16201621

16211622
for ($i = 0, $total = count($this->QBSet); $i < $total; $i += $batchSize) {
16221623
$sql = $this->_insertBatch($this->db->protectIdentifiers($table, true, null, false), $this->QBKeys, array_slice($this->QBSet, $i, $batchSize));
16231624

16241625
if ($this->testMode) {
1625-
$affectedRows++;
1626+
$savedSQL[] = $sql;
16261627
} else {
16271628
$this->db->query($sql, $this->binds, false);
16281629
$affectedRows += $this->db->affectedRows();
@@ -1633,7 +1634,7 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
16331634
$this->resetWrite();
16341635
}
16351636

1636-
return $affectedRows;
1637+
return $this->testMode ? $savedSQL : $affectedRows;
16371638
}
16381639

16391640
/**

0 commit comments

Comments
 (0)