Skip to content

Commit

Permalink
Merge branch 'QA'
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Nov 1, 2019
2 parents 1a073cd + 4a919ae commit 3edeac3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fix for PHP deprecations messages about implode for php 7.4+ (#258)
* Parse CHECK keyword on table definition (#264)
* Parse truncate statement (#221)
* Fix wrong parsing of partitions (#265)

## [5.0.0] - 2019-05-09

Expand Down
14 changes: 10 additions & 4 deletions src/Components/PartitionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,16 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$ret->name = $token->value;

// Looking ahead for a 'VALUES' keyword.
$idx = $list->idx;
$list->getNext();
$nextToken = $list->getNext();
$list->idx = $idx;
// Loop until the end of the partition name (delimited by a whitespace)
while ($nextToken = $list->tokens[++$list->idx]) {
if ($nextToken->type !== Token::TYPE_NONE) {
break;
}
$ret->name .= $nextToken->value;
}
$idx = $list->idx--;
// Get the first token after the white space.
$nextToken = $list->tokens[++$idx];

$state = ($nextToken->type === Token::TYPE_KEYWORD)
&& ($nextToken->value === 'VALUES')
Expand Down
12 changes: 12 additions & 0 deletions tests/Components/PartitionDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ public function testParse()
$this->assertEquals('LESS THAN', $component->type);
$this->assertEquals('(1990)', $component->expr->expr);
}

public function testParseNameWithUnderscore()
{
$component = PartitionDefinition::parse(
new Parser(),
$this->getTokensList('PARTITION 2017_12 VALUES LESS THAN (\'2018-01-01 00:00:00\') ENGINE = MyISAM')
);
$this->assertFalse($component->isSubpartition);
$this->assertEquals('2017_12', $component->name);
$this->assertEquals('LESS THAN', $component->type);
$this->assertEquals('(\'2018-01-01 00:00:00\')', $component->expr->expr);
}
}

0 comments on commit 3edeac3

Please sign in to comment.