Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- Enh #1201: Make `$psrCache` parameter of `SchemaCache` constructor and `$schemaCache` parameter of
`AbstractSchema` and `AbstractPdoConnection` constructors optional, remove `psr/simple-cache-implementation` from
`require` in `composer.json` (@vjik)
- Bug #1202: Fix `ColumnDefinitionParser` to parse an unquoted `DEFAULT NULL` as SQL `NULL` instead of the string
`'NULL'` (@Lugat)

## 2.0.1 February 09, 2026

Expand Down
10 changes: 8 additions & 2 deletions src/Syntax/ColumnDefinitionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use function preg_match_all;
use function preg_replace;
use function str_replace;
use function strcasecmp;
use function strlen;
use function strtolower;
use function substr;
Expand All @@ -22,7 +23,7 @@
* check?: string,
* collation?: string,
* comment?: string,
* defaultValueRaw?: string,
* defaultValueRaw?: string|null,
* extra?: string,
* notNull?: bool,
* unique?: bool,
Expand All @@ -42,7 +43,7 @@ class ColumnDefinitionParser
* check?: string,
* collation?: string,
* comment?: string,
* defaultValueRaw?: string,
* defaultValueRaw?: string|null,
* dimension?: positive-int,
* extra?: string,
* notNull?: bool,
Expand Down Expand Up @@ -115,6 +116,11 @@ protected function extraInfo(string $extra): array
$extra = $this->parseBoolValue($extra, '/\s*\bUNIQUE\b/i', 'unique', $info);
$extra = $this->parseBoolValue($extra, '/\s*\bNOT\s+NULL\b/i', 'notNull', $info);

/** @psalm-var ExtraInfo $info */
if (isset($info['defaultValueRaw']) && strcasecmp($info['defaultValueRaw'], 'NULL') === 0) {
$info['defaultValueRaw'] = null;
}

if (empty($info['notNull'])) {
$extra = $this->parseBoolValue($extra, '/\s*\bNULL\b/i', 'notNull', $info);

Expand Down
6 changes: 5 additions & 1 deletion tests/Provider/ColumnDefinitionParserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public static function parse(): array
['text NULL', ['type' => 'text', 'notNull' => false]],
['text COLLATE utf8mb4', ['type' => 'text', 'collation' => 'utf8mb4']],
["text COMPRESSION 'LZ4'", ['type' => 'text', 'extra' => "COMPRESSION 'LZ4'"]],
['text DEFAULT NULL', ['type' => 'text', 'defaultValueRaw' => 'NULL']],
['text DEFAULT NULL', ['type' => 'text', 'defaultValueRaw' => null]],
['int default null', ['type' => 'int', 'defaultValueRaw' => null]],
['int NULL DEFAULT NULL', ['type' => 'int', 'defaultValueRaw' => null, 'notNull' => false]],
['int DEFAULT 5', ['type' => 'int', 'defaultValueRaw' => '5']],
["varchar(10) DEFAULT 'NULL'", ['type' => 'varchar', 'size' => 10, 'defaultValueRaw' => "'NULL'"]],
["text DEFAULT 'value'", ['type' => 'text', 'defaultValueRaw' => "'value'"]],
['varchar(36) DEFAULT uuid()', ['type' => 'varchar', 'size' => 36, 'defaultValueRaw' => 'uuid()']],
['varchar(36) DEFAULT uuid()::varchar(36)', ['type' => 'varchar', 'size' => 36, 'defaultValueRaw' => 'uuid()::varchar(36)']],
Expand Down
Loading