Skip to content

Commit 26f786f

Browse files
committed
fix: SQLite3 Forge::modifyColumn() changes numeric default value
See #8457 (comment)
1 parent eafb2d2 commit 26f786f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

system/Database/SQLite3/Table.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,15 @@ protected function formatFields($fields)
399399
// 'NULL' means that the default value is NULL.
400400
$return[$field->name]['default'] = null;
401401
} else {
402-
$return[$field->name]['default'] = trim($field->default, "'");
402+
$default = trim($field->default, "'");
403+
404+
if ($this->isIntegerType($field->type)) {
405+
$default = (int) $default;
406+
} elseif ($this->isNumericType($field->type)) {
407+
$default = (float) $default;
408+
}
409+
410+
$return[$field->name]['default'] = $default;
403411
}
404412

405413
if ($field->primary_key) {
@@ -413,6 +421,30 @@ protected function formatFields($fields)
413421
return $return;
414422
}
415423

424+
/**
425+
* Is INTEGER type?
426+
*
427+
* @param string $type SQLite data type (case-insensitive)
428+
*
429+
* @see https://www.sqlite.org/datatype3.html
430+
*/
431+
private function isIntegerType(string $type): bool
432+
{
433+
return strpos(strtoupper($type), 'INT') !== false;
434+
}
435+
436+
/**
437+
* Is NUMERIC type?
438+
*
439+
* @param string $type SQLite data type (case-insensitive)
440+
*
441+
* @see https://www.sqlite.org/datatype3.html
442+
*/
443+
private function isNumericType(string $type): bool
444+
{
445+
return in_array(strtoupper($type), ['NUMERIC', 'DECIMAL'], true);
446+
}
447+
416448
/**
417449
* Converts keys retrieved from the database to
418450
* the format needed to create later.

0 commit comments

Comments
 (0)