Skip to content

Commit 3172645

Browse files
authored
Fix SQLite defaults for boolean type (#922)
* fix: sqlite defaults for boolean type are always 0 or 1 * update cakephp dependencies
1 parent aa90092 commit 3172645

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
},
2424
"require": {
2525
"php": ">=8.1",
26-
"cakephp/cache": "^5.2",
27-
"cakephp/orm": "^5.2",
26+
"cakephp/cache": "^5.2.9",
27+
"cakephp/database": "^5.2.9",
28+
"cakephp/orm": "^5.2.9",
2829
"robmorgan/phinx": "^0.16.10"
2930
},
3031
"require-dev": {
3132
"cakephp/bake": "^3.3",
32-
"cakephp/cakephp": "^5.2.5",
33+
"cakephp/cakephp": "^5.2.9",
3334
"cakephp/cakephp-codesniffer": "^5.0",
3435
"phpunit/phpunit": "^10.5.5 || ^11.1.3 || ^12.2.4"
3536
},

src/Db/Adapter/SqliteAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ public function truncateTable(string $tableName): void
466466
*/
467467
protected function parseDefaultValue(mixed $default, string $columnType): mixed
468468
{
469-
if ($default === null) {
470-
return null;
469+
if (!is_string($default)) {
470+
return $default;
471471
}
472472

473473
// split the input into tokens

tests/TestCase/Db/Adapter/SqliteAdapterTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,10 +3147,10 @@ public static function provideDefaultValues()
31473147
'Integer 3' => ['create table t(a integer default +1)', 1],
31483148
'Integer 4' => ['create table t(a integer default 2112)', 2112],
31493149
'Integer 5' => ['create table t(a integer default 002112)', 2112],
3150-
'Integer boolean 1' => ['create table t(a boolean default 1)', true],
3151-
'Integer boolean 2' => ['create table t(a boolean default 0)', false],
3152-
'Integer boolean 3' => ['create table t(a boolean default -1)', -1],
3153-
'Integer boolean 4' => ['create table t(a boolean default 2)', 2],
3150+
'Integer boolean 1' => ['create table t(a boolean default 1)', 1],
3151+
'Integer boolean 2' => ['create table t(a boolean default 0)', 0],
3152+
'Integer boolean 3' => ['create table t(a boolean default -1)', 0],
3153+
'Integer boolean 4' => ['create table t(a boolean default 2)', 0],
31543154
'Float 1' => ['create table t(a float default 1.0)', 1.0],
31553155
'Float 2' => ['create table t(a float default +1.0)', 1.0],
31563156
'Float 3' => ['create table t(a float default -1.0)', -1.0],
@@ -3184,12 +3184,12 @@ public function testGetColumnsForBooleanDefaults($tableDef, $exp)
31843184
public static function provideBooleanDefaultValues()
31853185
{
31863186
return [
3187-
'True LC' => ['create table t(a boolean default true)', true],
3188-
'True UC' => ['create table t(a boolean default TRUE)', true],
3189-
'True MC' => ['create table t(a boolean default TRue)', true],
3190-
'False LC' => ['create table t(a boolean default false)', false],
3191-
'False UC' => ['create table t(a boolean default FALSE)', false],
3192-
'False MC' => ['create table t(a boolean default FALse)', false],
3187+
'True LC' => ['create table t(a boolean default true)', 1],
3188+
'True UC' => ['create table t(a boolean default TRUE)', 1],
3189+
'True MC' => ['create table t(a boolean default TRue)', 1],
3190+
'False LC' => ['create table t(a boolean default false)', 0],
3191+
'False UC' => ['create table t(a boolean default FALSE)', 0],
3192+
'False MC' => ['create table t(a boolean default FALse)', 0],
31933193
];
31943194
}
31953195

0 commit comments

Comments
 (0)