From 7c0af694d43584c72138dd26440a30b0d436f6f8 Mon Sep 17 00:00:00 2001 From: Ahmat Arnal Kastana <41889734+arnal1@users.noreply.github.com> Date: Fri, 29 Oct 2021 14:02:10 +0700 Subject: [PATCH] Update Batch.php Add disable backtic to insert --- src/Batch.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Batch.php b/src/Batch.php index 83d4aa3..6720837 100644 --- a/src/Batch.php +++ b/src/Batch.php @@ -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) { @@ -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)) {