Skip to content

Commit

Permalink
:octocat: boolean field fix
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Aug 1, 2019
1 parent a4c9098 commit 4866ccf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Dialects/Firebird.php
Expand Up @@ -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.'\'';
}
Expand Down
3 changes: 3 additions & 0 deletions src/Dialects/MSSQL.php
Expand Up @@ -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.'\'';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dialects/MySQL.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Dialects/Postgres.php
Expand Up @@ -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';
Expand Down

0 comments on commit 4866ccf

Please sign in to comment.