Skip to content

Commit 6ffb86e

Browse files
committed
Support for BOOLEAN column type
1 parent 3be4c68 commit 6ffb86e

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

src/DataType.php

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ final class DataType
3737
const TIMESTAMP = 'TIMESTAMP';
3838
const DECIMAL = 'DECIMAL';
3939
const NUMERIC = 'NUMERIC';
40+
const BOOLEAN = 'BOOLEAN';
4041

4142
private function __construct()
4243
{

src/Parser/CreateTableParser.php

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ public static function parseFieldType(array &$tokens, bool $allowArbitaryType =
478478
case 'BLOB':
479479
case 'MEDIUMBLOB':
480480
case 'LONGBLOB':
481+
case 'BOOLEAN':
481482
break;
482483
case 'TINYINT':
483484
case 'SMALLINT':

src/Processor/CreateProcessor.php

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ private static function getDefinitionColumn(Query\MysqlColumnType $stmt) : Colum
147147
case DataType::BIT:
148148
case DataType::MEDIUMINT:
149149
case DataType::BIGINT:
150+
case DataType::BOOLEAN:
150151
if ($stmt->null === null) {
151152
$stmt->null = true;
152153
}
@@ -249,6 +250,7 @@ private static function getIntegerDefinitionColumn(Query\MysqlColumnType $stmt)
249250

250251
switch (strtoupper($stmt->type)) {
251252
case DataType::TINYINT:
253+
case DataType::BOOLEAN:
252254
return new Column\TinyInt($unsigned, $display_width);
253255

254256
case DataType::SMALLINT:

tests/EndToEndTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,24 @@ public function testSelectNullableFields()
10921092
);
10931093
}
10941094

1095+
public function testBoolean()
1096+
{
1097+
$pdo = self::getConnectionToFullDB(false, false);
1098+
1099+
$query = $pdo->prepare("SELECT `id`, `enabled` FROM `enemies`");
1100+
$query->execute();
1101+
1102+
$this->assertSame(
1103+
[
1104+
['id' => 1, 'enabled' => 1],
1105+
['id' => 2, 'enabled' => 0],
1106+
['id' => 3, 'enabled' => 0],
1107+
['id' => 4, 'enabled' => 1]
1108+
],
1109+
$query->fetchAll(\PDO::FETCH_ASSOC)
1110+
);
1111+
}
1112+
10951113
private static function getPdo(string $connection_string, bool $strict_mode = false) : \PDO
10961114
{
10971115
$options = $strict_mode ? [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode="STRICT_ALL_TABLES"'] : [];

tests/fixtures/bulk_enemy_insert.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
INSERT INTO `enemies`
2-
(`id`, `character_id`, `enemy_id`)
2+
(`id`, `character_id`, `enemy_id`, `enabled`)
33
VALUES
4-
(1, 1, 5),
5-
(2, 2, 5),
6-
(3, 3, 6),
7-
(4, 1, 11)
4+
(1, 1, 5, true),
5+
(2, 2, 5, false),
6+
(3, 3, 6, false),
7+
(4, 1, 11, true)

tests/fixtures/create_table.sql

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CREATE TABLE `enemies` (
2828
`id` int(10) NOT NULL AUTO_INCREMENT,
2929
`character_id` int(10) NOT NULL,
3030
`enemy_id` int(10) NOT NULL,
31+
`enabled` boolean NOT NULL DEFAULT true,
3132
PRIMARY KEY (`id`),
3233
KEY `character_id` (`character_id`),
3334
KEY `enemy_id` (`enemy_id`)

0 commit comments

Comments
 (0)