Skip to content

Commit dcb614b

Browse files
Michael Hahniamcal
authored andcommitted
Set null to true for fields that default to NULL
1 parent c5412e7 commit dcb614b

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/SQLParser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ function parse_field($tokens){
689689
# [DEFAULT default_value]
690690
if (count($tokens) >= 1 && StrToUpper($tokens[0]) == 'DEFAULT'){
691691
$f['default'] = $this->decode_value($tokens[1]);
692+
if ($f['default'] === 'NULL'){
693+
$f['null'] = true;
694+
}
695+
692696
array_shift($tokens);
693697
array_shift($tokens);
694698
}

tests/FieldTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,17 @@ function testFieldOptions(){
317317
# [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
318318
# [STORAGE {DISK|MEMORY|DEFAULT}]
319319
# [reference_definition]
320+
321+
$fields = $this->get_fields("bar VARCHAR(255) DEFAULT NULL");
322+
$this->assertEquals([
323+
[
324+
'name' => "bar",
325+
'type' => "VARCHAR",
326+
'length' => 255,
327+
'default' => 'NULL',
328+
'null' => true,
329+
]
330+
], $fields);
320331
}
321332

322333
function testVirtualOptions(){

0 commit comments

Comments
 (0)