Skip to content

Commit 67c872a

Browse files
committed
Actually fix the ALTER TABLE … ENUM type column operation.
1 parent 6844b88 commit 67c872a

File tree

6 files changed

+16
-50
lines changed

6 files changed

+16
-50
lines changed

src/Components/AlterOperation.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,33 +425,32 @@ public static function parse(Parser $parser, TokensList $list, array $options =
425425
break;
426426
}
427427
} elseif (! self::checkIfTokenQuotedSymbol($token)) {
428-
if (! empty(Parser::$statementParsers[$token->value])) {
428+
// If the current token is "SET" or "ENUM", we want to avoid the token between their parenthesis in
429+
// the unknown tokens.
430+
if (in_array($token->value, ['SET', 'ENUM'], true)) {
429431
$list->idx++; // Ignore the current token
430432
$nextToken = $list->getNext();
431433

432-
if (
433-
in_array($token->value, ['SET', 'ENUM'], true)
434-
&& $nextToken !== null
435-
&& $nextToken->value === '('
436-
) {
437-
// To avoid adding the tokens between the SET() or ENUM() parentheses to the unknown tokens
434+
if ($nextToken !== null && $nextToken->value === '(') {
438435
$list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')');
439-
} elseif (
440-
in_array($token->value, ['SET', 'ENUM'], true)
441-
&& $nextToken !== null
442-
&& $nextToken->value === 'DEFAULT'
443-
) {
436+
} elseif ($nextToken !== null && $nextToken->value === 'DEFAULT') {
444437
// to avoid adding the `DEFAULT` token to the unknown tokens.
445438
++$list->idx;
446439
} else {
447-
// We have reached the end of ALTER operation and suddenly found
448-
// a start to new statement, but have not find a delimiter between them
449440
$parser->error(
450441
'A new statement was found, but no delimiter between it and the previous one.',
451442
$token
452443
);
453444
break;
454445
}
446+
} elseif (! empty(Parser::$statementParsers[$token->value])) {
447+
// We have reached the end of ALTER operation and suddenly found
448+
// a start to new statement, but have not found a delimiter between them
449+
$parser->error(
450+
'A new statement was found, but no delimiter between it and the previous one.',
451+
$token
452+
);
453+
break;
455454
} elseif (
456455
(array_key_exists($arrayKey, self::$databaseOptions)
457456
|| array_key_exists($arrayKey, self::$tableOptions))

tests/Parser/AlterStatementTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public static function alterProvider(): array
4949
['parser/parseAlterTableDropAddIndex1'],
5050
['parser/parseAlterTableDropColumn1'],
5151
['parser/parseAlterTableModifyColumn'],
52+
['parser/parseAlterTableModifyColumnEnum1'],
53+
['parser/parseAlterTableModifyColumnEnum2'],
54+
['parser/parseAlterTableModifyColumnEnum3'],
5255
['parser/parseAlterWithInvisible'],
5356
['parser/parseAlterTableCharacterSet1'],
5457
['parser/parseAlterTableCharacterSet2'],

tests/data/parser/parseAlter9.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,6 @@
336336
{
337337
"@type": "@16"
338338
},
339-
{
340-
"@type": "@17"
341-
},
342-
{
343-
"@type": "@18"
344-
},
345-
{
346-
"@type": "@19"
347-
},
348-
{
349-
"@type": "@20"
350-
},
351339
{
352340
"@type": "@21"
353341
},

tests/data/parser/parseAlterTableModifyColumnEnum1.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,6 @@
248248
{
249249
"@type": "@14"
250250
},
251-
{
252-
"@type": "@15"
253-
},
254-
{
255-
"@type": "@16"
256-
},
257-
{
258-
"@type": "@17"
259-
},
260-
{
261-
"@type": "@18"
262-
},
263251
{
264252
"@type": "@19"
265253
}

tests/data/parser/parseAlterTableModifyColumnEnum2.out

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@
248248
{
249249
"@type": "@14"
250250
},
251-
{
252-
"@type": "@15"
253-
},
254-
{
255-
"@type": "@16"
256-
},
257251
{
258252
"@type": "@19"
259253
}

tests/data/parser/parseAlterTableModifyColumnEnum3.out

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@
248248
{
249249
"@type": "@14"
250250
},
251-
{
252-
"@type": "@15"
253-
},
254-
{
255-
"@type": "@16"
256-
},
257251
{
258252
"@type": "@19"
259253
}

0 commit comments

Comments
 (0)