Skip to content

Commit adfe314

Browse files
committed
Fix ALTER regression
- Fixes #511 - Reverts #485 Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 1be109e commit adfe314

12 files changed

+1756
-14
lines changed

src/Components/AlterOperation.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,33 +426,26 @@ public static function parse(Parser $parser, TokensList $list, array $options =
426426
} elseif (($token->value === ',') && ($brackets === 0)) {
427427
break;
428428
}
429-
} elseif (! self::checkIfTokenQuotedSymbol($token)) {
430-
// If the current token is "SET" or "ENUM", we want to avoid the token between their parenthesis in
431-
// the unknown tokens.
432-
if (in_array($token->value, ['SET', 'ENUM'], true)) {
429+
} elseif (! self::checkIfTokenQuotedSymbol($token) && $token->type !== Token::TYPE_STRING) {
430+
if (isset(Parser::$STATEMENT_PARSERS[$arrayKey]) && Parser::$STATEMENT_PARSERS[$arrayKey] !== '') {
433431
$list->idx++; // Ignore the current token
434432
$nextToken = $list->getNext();
435433

436-
if ($nextToken !== null && $nextToken->value === '(') {
434+
if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') {
435+
// To avoid adding the tokens between the SET() parentheses to the unknown tokens
437436
$list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')');
438-
} elseif ($nextToken !== null && $nextToken->value === 'DEFAULT') {
437+
} elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') {
439438
// to avoid adding the `DEFAULT` token to the unknown tokens.
440439
++$list->idx;
441440
} else {
441+
// We have reached the end of ALTER operation and suddenly found
442+
// a start to new statement, but have not found a delimiter between them
442443
$parser->error(
443444
'A new statement was found, but no delimiter between it and the previous one.',
444445
$token
445446
);
446447
break;
447448
}
448-
} elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
449-
// We have reached the end of ALTER operation and suddenly found
450-
// a start to new statement, but have not found a delimiter between them
451-
$parser->error(
452-
'A new statement was found, but no delimiter between it and the previous one.',
453-
$token
454-
);
455-
break;
456449
} elseif (
457450
(array_key_exists($arrayKey, self::$DB_OPTIONS)
458451
|| array_key_exists($arrayKey, self::$TABLE_OPTIONS))

tests/Misc/BugsTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public function bugProvider(): array
2525
['bugs/gh9'],
2626
['bugs/gh14'],
2727
['bugs/gh16'],
28+
['bugs/gh234'],
2829
['bugs/gh317'],
30+
['bugs/gh478'],
2931
['bugs/gh508'],
32+
['bugs/gh511'],
3033
['bugs/pma11800'],
3134
['bugs/pma11836'],
3235
['bugs/pma11843'],

tests/data/bugs/gh234.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `mail_template` CHANGE COLUMN `mtpl_group` `mtpl_group` ENUM('ORDER') NULL DEFAULT NULL ;

0 commit comments

Comments
 (0)