Fix MySQL error were prepared statement contains too many placeholders (#10153)
* Fixes a MySQL error were the prepared statement contains too many placeholders. Modifies dbBulkInsert to run array_chunk on incoming data and inserts those smaller chunks. * Trying to address some automatic checks about blank lines. * Trying to make Code Climate happy with reduced cognitive complexity. * Trying to make Code Climate happy with reduced cognitive complexity.
This commit is contained in:
parent
a46fc9d329
commit
223d3070d5
|
@ -144,21 +144,27 @@ function dbBulkInsert($data, $table)
|
|||
if (empty($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure we have fields to insert
|
||||
$fields = array_keys(reset($data));
|
||||
if (empty($fields)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// $result = Eloquent::DB()->insert($sql.$values);
|
||||
$result = Eloquent::DB()->table($table)->insert((array)$data);
|
||||
// Break into managable chunks to prevent situations where insert
|
||||
// fails due to prepared statement having too many placeholders.
|
||||
$data_chunks = array_chunk($data, 10000, true);
|
||||
|
||||
recordDbStatistic('insert', $time_start);
|
||||
return $result;
|
||||
} catch (PDOException $pdoe) {
|
||||
// FIXME query?
|
||||
dbHandleException(new QueryException("Bulk insert $table", $data, $pdoe));
|
||||
foreach ($data_chunks as $data_chunk) {
|
||||
try {
|
||||
$result = Eloquent::DB()->table($table)->insert((array)$data_chunk);
|
||||
|
||||
recordDbStatistic('insert', $time_start);
|
||||
return $result;
|
||||
} catch (PDOException $pdoe) {
|
||||
// FIXME query?
|
||||
dbHandleException(new QueryException("Bulk insert $table", $data_chunk, $pdoe));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue