diff --git a/src/DataType.php b/src/DataType.php index 876b0963..9dc52277 100644 --- a/src/DataType.php +++ b/src/DataType.php @@ -37,6 +37,7 @@ final class DataType const TIMESTAMP = 'TIMESTAMP'; const DECIMAL = 'DECIMAL'; const NUMERIC = 'NUMERIC'; + const BOOLEAN = 'BOOLEAN'; private function __construct() { diff --git a/src/Parser/CreateTableParser.php b/src/Parser/CreateTableParser.php index 6d24a881..23d8dd17 100644 --- a/src/Parser/CreateTableParser.php +++ b/src/Parser/CreateTableParser.php @@ -478,6 +478,7 @@ public static function parseFieldType(array &$tokens, bool $allowArbitaryType = case 'BLOB': case 'MEDIUMBLOB': case 'LONGBLOB': + case 'BOOLEAN': break; case 'TINYINT': case 'SMALLINT': diff --git a/src/Processor/CreateProcessor.php b/src/Processor/CreateProcessor.php index cb1acf80..16cb14f3 100644 --- a/src/Processor/CreateProcessor.php +++ b/src/Processor/CreateProcessor.php @@ -147,6 +147,7 @@ private static function getDefinitionColumn(Query\MysqlColumnType $stmt) : Colum case DataType::BIT: case DataType::MEDIUMINT: case DataType::BIGINT: + case DataType::BOOLEAN: if ($stmt->null === null) { $stmt->null = true; } @@ -249,6 +250,7 @@ private static function getIntegerDefinitionColumn(Query\MysqlColumnType $stmt) switch (strtoupper($stmt->type)) { case DataType::TINYINT: + case DataType::BOOLEAN: return new Column\TinyInt($unsigned, $display_width); case DataType::SMALLINT: diff --git a/tests/EndToEndTest.php b/tests/EndToEndTest.php index a594140e..6e65adc5 100644 --- a/tests/EndToEndTest.php +++ b/tests/EndToEndTest.php @@ -1092,6 +1092,24 @@ public function testSelectNullableFields() ); } + public function testBoolean() + { + $pdo = self::getConnectionToFullDB(false, false); + + $query = $pdo->prepare("SELECT `id`, `enabled` FROM `enemies`"); + $query->execute(); + + $this->assertSame( + [ + ['id' => 1, 'enabled' => 1], + ['id' => 2, 'enabled' => 0], + ['id' => 3, 'enabled' => 0], + ['id' => 4, 'enabled' => 1] + ], + $query->fetchAll(\PDO::FETCH_ASSOC) + ); + } + private static function getPdo(string $connection_string, bool $strict_mode = false) : \PDO { $options = $strict_mode ? [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode="STRICT_ALL_TABLES"'] : []; diff --git a/tests/fixtures/bulk_enemy_insert.sql b/tests/fixtures/bulk_enemy_insert.sql index 596329eb..2991f7a5 100644 --- a/tests/fixtures/bulk_enemy_insert.sql +++ b/tests/fixtures/bulk_enemy_insert.sql @@ -1,7 +1,7 @@ INSERT INTO `enemies` - (`id`, `character_id`, `enemy_id`) + (`id`, `character_id`, `enemy_id`, `enabled`) VALUES - (1, 1, 5), - (2, 2, 5), - (3, 3, 6), - (4, 1, 11) \ No newline at end of file + (1, 1, 5, true), + (2, 2, 5, false), + (3, 3, 6, false), + (4, 1, 11, true) \ No newline at end of file diff --git a/tests/fixtures/create_table.sql b/tests/fixtures/create_table.sql index f207482c..edd4604f 100644 --- a/tests/fixtures/create_table.sql +++ b/tests/fixtures/create_table.sql @@ -28,6 +28,7 @@ CREATE TABLE `enemies` ( `id` int(10) NOT NULL AUTO_INCREMENT, `character_id` int(10) NOT NULL, `enemy_id` int(10) NOT NULL, + `enabled` boolean NOT NULL DEFAULT true, PRIMARY KEY (`id`), KEY `character_id` (`character_id`), KEY `enemy_id` (`enemy_id`)