Skip to content

Commit d0f9363

Browse files
committed
fix: fix boolean values in batch update
1 parent 063d73f commit d0f9363

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Batch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function update(Model $table, array $values, string $index = null, bool $
7474
foreach (array_keys($val) as $field) {
7575
if ($field !== $index) {
7676
$finalField = $raw ? Common::mysql_escape($val[$field]) : "'" . Common::mysql_escape($val[$field]) . "'";
77-
$value = (is_null($val[$field]) ? 'NULL' : $finalField);
77+
$value = (is_null($val[$field]) ? 'NULL' : Common::convertBoolean($finalField));
7878
if ($driver == 'pgsql')
7979
$final[$field][] = 'WHEN ' . $index . ' = \'' . $val[$index] . '\' THEN ' . $value . ' ';
8080
else

src/Common/Common.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,23 @@ public static function mysql_escape($fieldValue)
2626

2727
return $fieldValue;
2828
}
29+
30+
/**
31+
* Convert boolean values to 0 or 1.
32+
*
33+
* @param $fieldValue
34+
* @return array|string|bool|string[]|bool[]
35+
*/
36+
public static function convertBoolean($fieldValue)
37+
{
38+
if (is_array($fieldValue)) {
39+
return array_map(__METHOD__, $fieldValue);
40+
}
41+
42+
if (is_bool($fieldValue)) {
43+
return (int) $fieldValue;
44+
}
45+
46+
return $fieldValue;
47+
}
2948
}

0 commit comments

Comments
 (0)