Skip to content

Commit c66c615

Browse files
committed
add ability to use raw query for update function
1 parent 4c942ec commit c66c615

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/LaravelBatch.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public function __construct(DatabaseManager $db)
4444
*
4545
* @return bool|int
4646
*/
47-
public function update(Model $table, array $values, string $index = null)
47+
public function update(Model $table, array $values, string $index = null, bool $raw = false)
4848
{
4949
$final = [];
5050
$ids = [];
5151

5252
if (!count($values)) {
5353
return false;
5454
}
55-
55+
5656
if (!isset($index) || empty($index)) {
5757
$index = $table->getKeyName();
5858
}
@@ -61,7 +61,8 @@ public function update(Model $table, array $values, string $index = null)
6161
$ids[] = $val[$index];
6262
foreach (array_keys($val) as $field) {
6363
if ($field !== $index) {
64-
$value = (is_null($val[$field]) ? 'NULL' : '"' . Common::mysql_escape($val[$field]) . '"');
64+
$finalField = $raw ? Common::mysql_escape($val[$field]) : '"' . Common::mysql_escape($val[$field]) . '"';
65+
$value = (is_null($val[$field]) ? 'NULL' : $finalField);
6566
$final[$field][] = 'WHEN `' . $index . '` = "' . $val[$index] . '" THEN ' . $value . ' ';
6667
}
6768
}
@@ -159,8 +160,7 @@ public function insert(Model $table, array $columns, array $values, int $batchSi
159160

160161
$valueString = implode(', ', $valueArray);
161162

162-
$query [] = "INSERT INTO `" . $this->getFullTableName($table) . "` (" . implode(',', $columns) . ") VALUES $valueString;";
163-
163+
$query[] = "INSERT INTO `" . $this->getFullTableName($table) . "` (" . implode(',', $columns) . ") VALUES $valueString;";
164164
}
165165

166166
if (count($query)) {

0 commit comments

Comments
 (0)