Skip to content

Commit 3edeac3

Browse files
committed
Merge branch 'QA'
Signed-off-by: William Desportes <[email protected]>
2 parents 1a073cd + 4a919ae commit 3edeac3

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Fix for PHP deprecations messages about implode for php 7.4+ (#258)
55
* Parse CHECK keyword on table definition (#264)
66
* Parse truncate statement (#221)
7+
* Fix wrong parsing of partitions (#265)
78

89
## [5.0.0] - 2019-05-09
910

src/Components/PartitionDefinition.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ public static function parse(Parser $parser, TokensList $list, array $options =
170170
$ret->name = $token->value;
171171

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

178184
$state = ($nextToken->type === Token::TYPE_KEYWORD)
179185
&& ($nextToken->value === 'VALUES')

tests/Components/PartitionDefinitionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,16 @@ public function testParse()
2020
$this->assertEquals('LESS THAN', $component->type);
2121
$this->assertEquals('(1990)', $component->expr->expr);
2222
}
23+
24+
public function testParseNameWithUnderscore()
25+
{
26+
$component = PartitionDefinition::parse(
27+
new Parser(),
28+
$this->getTokensList('PARTITION 2017_12 VALUES LESS THAN (\'2018-01-01 00:00:00\') ENGINE = MyISAM')
29+
);
30+
$this->assertFalse($component->isSubpartition);
31+
$this->assertEquals('2017_12', $component->name);
32+
$this->assertEquals('LESS THAN', $component->type);
33+
$this->assertEquals('(\'2018-01-01 00:00:00\')', $component->expr->expr);
34+
}
2335
}

0 commit comments

Comments
 (0)