From fe98a34d4c5e557fbc3c0ae1152f8570bcaf2991 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Fri, 1 Nov 2019 00:51:39 +0100 Subject: [PATCH 1/2] Fix #13951 wrong parsing partitions When partition names contain "_", the parser wasn't reading the full name, but stopped before the first "_". Signed-off-by: Hugues Peccatte --- src/Components/PartitionDefinition.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 71f73b866..841a16a4b 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -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_WHITESPACE) { + 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') From ccb20a1c7c1cbe75645f9d19a908bed4c98672fd Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Fri, 1 Nov 2019 09:36:57 +0100 Subject: [PATCH 2/2] Add test case to check partition name starting by a number Signed-off-by: Hugues Peccatte --- src/Components/PartitionDefinition.php | 2 +- tests/Components/PartitionDefinitionTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 841a16a4b..53da14894 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -172,7 +172,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = // Looking ahead for a 'VALUES' keyword. // Loop until the end of the partition name (delimited by a whitespace) while ($nextToken = $list->tokens[++$list->idx]) { - if ($nextToken->type === Token::TYPE_WHITESPACE) { + if ($nextToken->type !== Token::TYPE_NONE) { break; } $ret->name .= $nextToken->value; diff --git a/tests/Components/PartitionDefinitionTest.php b/tests/Components/PartitionDefinitionTest.php index 7edc21e88..3c9a84758 100644 --- a/tests/Components/PartitionDefinitionTest.php +++ b/tests/Components/PartitionDefinitionTest.php @@ -19,4 +19,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); + } }