Skip to content

Commit

Permalink
Fix ALTER regression
Browse files Browse the repository at this point in the history
- Fixes #511
- Reverts #485

Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Sep 19, 2023
1 parent 1be109e commit adfe314
Show file tree
Hide file tree
Showing 12 changed files with 1,756 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,33 +426,26 @@ public static function parse(Parser $parser, TokensList $list, array $options =
} elseif (($token->value === ',') && ($brackets === 0)) {
break;
}
} elseif (! self::checkIfTokenQuotedSymbol($token)) {
// If the current token is "SET" or "ENUM", we want to avoid the token between their parenthesis in
// the unknown tokens.
if (in_array($token->value, ['SET', 'ENUM'], true)) {
} elseif (! self::checkIfTokenQuotedSymbol($token) && $token->type !== Token::TYPE_STRING) {
if (isset(Parser::$STATEMENT_PARSERS[$arrayKey]) && Parser::$STATEMENT_PARSERS[$arrayKey] !== '') {
$list->idx++; // Ignore the current token
$nextToken = $list->getNext();

if ($nextToken !== null && $nextToken->value === '(') {
if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') {
// To avoid adding the tokens between the SET() parentheses to the unknown tokens
$list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')');
} elseif ($nextToken !== null && $nextToken->value === 'DEFAULT') {
} elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') {
// to avoid adding the `DEFAULT` token to the unknown tokens.
++$list->idx;
} else {
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not found a delimiter between them
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
);
break;
}
} elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not found a delimiter between them
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
);
break;
} elseif (
(array_key_exists($arrayKey, self::$DB_OPTIONS)
|| array_key_exists($arrayKey, self::$TABLE_OPTIONS))
Expand Down
3 changes: 3 additions & 0 deletions tests/Misc/BugsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public function bugProvider(): array
['bugs/gh9'],
['bugs/gh14'],
['bugs/gh16'],
['bugs/gh234'],
['bugs/gh317'],
['bugs/gh478'],
['bugs/gh508'],
['bugs/gh511'],
['bugs/pma11800'],
['bugs/pma11836'],
['bugs/pma11843'],
Expand Down
1 change: 1 addition & 0 deletions tests/data/bugs/gh234.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mail_template` CHANGE COLUMN `mtpl_group` `mtpl_group` ENUM('ORDER') NULL DEFAULT NULL ;
Loading

0 comments on commit adfe314

Please sign in to comment.