When i use insertBulk, it changes my indexes.
no new data!
$db->insertBulk('xf_lala_team', $insert, false, 'team_id = VALUES(team_id)');
=> changes my indexes
the same data than inserted before
$db->insertBulk('xf_lala_team', $insert, true, 'team_id = VALUES(team_id)');
=> updates my data and changes my indexes.
new data
$db->insertBulk('xf_lala_team', $insert, true, 'team_id = VALUES(team_id)');
=> inserts new data and doesn't change my indexes.
Example
first run, i insert 18 new columns with team_id from 1 to 18.
In the second run $insert is empty, then my columns will be change to 19 to 38.
no new data!
$db->insertBulk('xf_lala_team', $insert, false, 'team_id = VALUES(team_id)');
=> changes my indexes
the same data than inserted before
$db->insertBulk('xf_lala_team', $insert, true, 'team_id = VALUES(team_id)');
=> updates my data and changes my indexes.
new data
$db->insertBulk('xf_lala_team', $insert, true, 'team_id = VALUES(team_id)');
=> inserts new data and doesn't change my indexes.
Example
first run, i insert 18 new columns with team_id from 1 to 18.
In the second run $insert is empty, then my columns will be change to 19 to 38.
Code:
public function insertBulk($table, array $rows, $replaceInto = false, $onDupe = false, $modifier = '')
{
if (!$rows)
{
throw new \InvalidArgumentException('Rows must be provided to bulk insert');
}
$firstRow = reset($rows);
$cols = array_keys($firstRow);
$rowSql = [];
foreach ($rows AS $row)
{
$values = [];
foreach ($cols AS $col)
{
if (!array_key_exists($col, $row))
{
throw new \InvalidArgumentException("Row missing column $col in bulk insert");
}
$values[] = $this->quote($row[$col]);
}
$rowSql[] = '(' . implode(',', $values) . ')';
}
foreach ($cols AS &$col)
{
$col = "`$col`";
}
$keyword = ($replaceInto ? 'REPLACE' : 'INSERT');
if ($replaceInto)
{
$onDupe = false;
}
try
{
$res = $this->query(
"$keyword $modifier INTO `$table` (" . implode(', ', $cols) . ') VALUES '
. implode(",\n", $rowSql)
. ($onDupe ? " ON DUPLICATE KEY UPDATE $onDupe" : '')
);
return $res->rowsAffected();
}
catch (Exception $e)
{
return $this->processDbWriteException($table, $e);
}
}