diff --git a/src/SQLParser.php b/src/SQLParser.php index 5105744..6eeace8 100644 --- a/src/SQLParser.php +++ b/src/SQLParser.php @@ -108,7 +108,7 @@ private function _lex($sql){ # [ [ ] ] # # ::= ... - if (preg_match('!(\d+\.?\d*|\.\d+)!A', $sql, $m, 0, $pos)){ + if (preg_match('![-+]?(\d+\.?\d*|\.\d+)!A', $sql, $m, 0, $pos)){ $source_map[] = array($pos, strlen($m[0])); $pos += strlen($m[0]); continue; @@ -760,6 +760,11 @@ function parse_field($tokens){ # [UNIQUE [KEY] | [PRIMARY] KEY] # [COMMENT 'string'] + if (count($tokens) >= 1 && StrToUpper($tokens[0]) == 'COMMENT'){ + $f['comment'] = $this->decode_value($tokens[1]); + array_shift($tokens); + array_shift($tokens); + } # [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}] # [STORAGE {DISK|MEMORY|DEFAULT}] # [reference_definition] diff --git a/tests/FieldTest.php b/tests/FieldTest.php index c8b19a1..14709c6 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -335,6 +335,19 @@ function testFieldOptions(){ 'null' => true, ) ), $fields); + + $fields = $this->get_fields("bar INT NOT NULL DEFAULT -1"); + $this->assertEquals(array( + array( + 'name' => "bar", + 'type' => "INT", + 'default' => '-1', + 'null' => false, + ) + ), $fields); + + $fields = $this->get_fields("ucount int NOT NULL comment 'user count'"); + $this->assertEquals('user count', $fields[0]['comment']); } function testVirtualOptions(){