Skip to content

Commit cddd67c

Browse files
committed
Refactored setInsertBatch() to use new methods
1 parent e28461e commit cddd67c

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

system/Database/BaseBuilder.php

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,44 +1989,11 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
19891989
*/
19901990
public function setInsertBatch($key, string $value = '', ?bool $escape = null)
19911991
{
1992-
$key = $this->batchObjectToArray($key);
1993-
19941992
if (! is_array($key)) {
1995-
$key = [$key => $value];
1993+
$key = [[$key => $value]];
19961994
}
19971995

1998-
$escape = is_bool($escape) ? $escape : $this->db->protectIdentifiers;
1999-
2000-
$keys = array_keys($this->objectToArray(current($key)));
2001-
sort($keys);
2002-
2003-
foreach ($key as $row) {
2004-
$row = $this->objectToArray($row);
2005-
if (array_diff($keys, array_keys($row)) !== [] || array_diff(array_keys($row), $keys) !== []) {
2006-
// batch function above returns an error on an empty array
2007-
$this->QBSet[] = [];
2008-
2009-
return null;
2010-
}
2011-
2012-
ksort($row); // puts $row in the same order as our keys
2013-
2014-
$clean = [];
2015-
2016-
foreach ($row as $rowValue) {
2017-
$clean[] = $escape ? $this->db->escape($rowValue) : $rowValue;
2018-
}
2019-
2020-
$row = $clean;
2021-
2022-
$this->QBSet[] = '(' . implode(',', $row) . ')';
2023-
}
2024-
2025-
foreach ($keys as $k) {
2026-
$this->QBKeys[] = $this->db->protectIdentifiers($k, false);
2027-
}
2028-
2029-
return $this;
1996+
return $this->setData($key, $escape);
20301997
}
20311998

20321999
/**

0 commit comments

Comments
 (0)