From 4866ccfdcb3426977cb256a30621d815277d68a7 Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 2 Aug 2019 01:45:41 +0200 Subject: [PATCH] :octocat: boolean field fix --- src/Dialects/Firebird.php | 3 +++ src/Dialects/MSSQL.php | 3 +++ src/Dialects/MySQL.php | 2 +- src/Dialects/Postgres.php | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Dialects/Firebird.php b/src/Dialects/Firebird.php index ab30c9a..cae7ca0 100644 --- a/src/Dialects/Firebird.php +++ b/src/Dialects/Firebird.php @@ -162,6 +162,9 @@ public function fieldspec(string $name, string $type, $length = null, string $at case strtoupper($defaultValue) === 'NULL' && $isNull === true: $field[] = 'DEFAULT NULL'; break; + case $type === 'BOOLEAN': + $field[] = 'DEFAULT '.(preg_match('/^1|T|TRUE|YES$/i', $defaultValue) ? '1' : '0'); + break; default: $field[] = 'DEFAULT \''.$defaultValue.'\''; } diff --git a/src/Dialects/MSSQL.php b/src/Dialects/MSSQL.php index 3b3f8c7..a78d311 100644 --- a/src/Dialects/MSSQL.php +++ b/src/Dialects/MSSQL.php @@ -121,6 +121,9 @@ public function fieldspec(string $name, string $type, $length = null, string $at // @todo switch(true){ + case $type === 'BOOLEAN': + $field[] = 'DEFAULT '.(preg_match('/^1|T|TRUE|YES$/i', $defaultValue) ? '1' : '0'); + break; default: $field[] = 'DEFAULT \''.$defaultValue.'\''; } diff --git a/src/Dialects/MySQL.php b/src/Dialects/MySQL.php index 90b33b9..24fcb67 100644 --- a/src/Dialects/MySQL.php +++ b/src/Dialects/MySQL.php @@ -160,7 +160,7 @@ public function fieldspec(string $name, string $type, $length = null, string $at $field[] = 'DEFAULT b\''.preg_replace('/[^01]/', '0', $defaultValue).'\''; break; case $type === 'BOOLEAN': - $field[] = 'DEFAULT '.preg_match('/^1|T|TRUE|YES$/i', $defaultValue) ? 'TRUE' : 'FALSE'; + $field[] = 'DEFAULT '.(preg_match('/^1|T|TRUE|YES$/i', $defaultValue) ? 'TRUE' : 'FALSE'); break; case $type === 'BINARY' || $type === 'VARBINARY': $field[] = 'DEFAULT 0x'.$defaultValue; diff --git a/src/Dialects/Postgres.php b/src/Dialects/Postgres.php index 91d3fe1..d725981 100644 --- a/src/Dialects/Postgres.php +++ b/src/Dialects/Postgres.php @@ -178,7 +178,7 @@ public function fieldspec(string $name, string $type, $length = null, string $at $field[] = 'DEFAULT b\''.preg_replace('/[^01]/', '0', $defaultValue).'\''; break; case $type === 'BOOLEAN': - $field[] = 'DEFAULT '.preg_match('/^1|T|TRUE|YES$/i', $defaultValue) ? 'TRUE' : 'FALSE'; + $field[] = 'DEFAULT '.(preg_match('/^1|T|TRUE|YES$/i', $defaultValue) ? 'TRUE' : 'FALSE'); break; case strtoupper($defaultValue) === 'NULL' && $isNull === true: $field[] = 'DEFAULT NULL';