diff --git a/src/Processor/CreateProcessor.php b/src/Processor/CreateProcessor.php index bf6d14ee..89b7d223 100644 --- a/src/Processor/CreateProcessor.php +++ b/src/Processor/CreateProcessor.php @@ -147,6 +147,10 @@ private static function getDefinitionColumn(Query\MysqlColumnType $stmt) : Colum case DataType::BIT: case DataType::MEDIUMINT: case DataType::BIGINT: + if ($stmt->null === null) { + $stmt->null = true; + } + return self::getIntegerDefinitionColumn($stmt); case DataType::FLOAT: diff --git a/tests/EndToEndTest.php b/tests/EndToEndTest.php index 699d95b1..30e8016d 100644 --- a/tests/EndToEndTest.php +++ b/tests/EndToEndTest.php @@ -983,6 +983,30 @@ public function testDropTable(string $table): void ); } + public function testSelectNullableFields() + { + $pdo = self::getConnectionToFullDB(false); + + $query = $pdo->prepare("SELECT nullable_field, nullable_field_default_0 FROM `video_game_characters` WHERE `id` = 1"); + $query->execute(); + + $this->assertSame( + ['nullable_field' => null, 'nullable_field_default_0' => 0], + $query->fetch(\PDO::FETCH_ASSOC) + ); + + $query = $pdo->prepare("UPDATE `video_game_characters` SET `nullable_field_default_0` = NULL, `nullable_field` = NULL WHERE `id` = 1"); + $query->execute(); + + $query = $pdo->prepare("SELECT nullable_field, nullable_field_default_0 FROM `video_game_characters` WHERE `id` = 1"); + $query->execute(); + + $this->assertSame( + ['nullable_field' => null, 'nullable_field_default_0' => null], + $query->fetch(\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/create_table.sql b/tests/fixtures/create_table.sql index eb232321..3b5bf1c2 100644 --- a/tests/fixtures/create_table.sql +++ b/tests/fixtures/create_table.sql @@ -10,6 +10,7 @@ CREATE TABLE `video_game_characters` ( `powerups` tinyint(3) UNSIGNED NOT NULL DEFAULT '0', `skills` varchar(1000) NOT NULL DEFAULT '', `nullable_field` tinyint(3) DEFAULT NULL, + `nullable_field_default_0` tinyint(3) DEFAULT '0', `some_float` float DEFAULT '0.00', `total_games` int(11) UNSIGNED NOT NULL DEFAULT '0', `lives` int(11) UNSIGNED NOT NULL DEFAULT '0',