Skip to content

Commit

Permalink
Merge pull request #78 from arnal1/add-disable-bactick-to-insert
Browse files Browse the repository at this point in the history
Update Batch.php
  • Loading branch information
mavinoo authored Oct 30, 2021
2 parents 98ea0ba + 7c0af69 commit bff39ec
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,17 @@ public function insert(Model $table, array $columns, array $values, int $batchSi
}
}

foreach ($columns as $key => $column) {
$columns[$key] = '`' . Common::mysql_escape($column) . '`';
$connection = config('database.default');
$driver = config("database.connections.{$connection}.driver");

if (Common::disableBacktick($driver)) {
foreach ($columns as $key => $column) {
$columns[$key] = '"' . Common::mysql_escape($column) . '"';
}
} else {
foreach ($columns as $key => $column) {
$columns[$key] = '`' . Common::mysql_escape($column) . '`';
}
}

foreach ($values as $value) {
Expand All @@ -335,7 +344,11 @@ public function insert(Model $table, array $columns, array $values, int $batchSi

$ignoreStmt = $insertIgnore ? ' IGNORE ' : '';

$query[] = 'INSERT ' . $ignoreStmt . ' INTO `' . $this->getFullTableName($table) . '` (' . implode(',', $columns) . ") VALUES $valueString;";
if (Common::disableBacktick($driver)) {
$query[] = 'INSERT ' . $ignoreStmt . ' INTO "' . $this->getFullTableName($table) . '" (' . implode(',', $columns) . ") VALUES $valueString;";
} else {
$query[] = 'INSERT ' . $ignoreStmt . ' INTO `' . $this->getFullTableName($table) . '` (' . implode(',', $columns) . ") VALUES $valueString;";
}
}

if (count($query)) {
Expand Down

0 comments on commit bff39ec

Please sign in to comment.