diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index 261187ec0..a444d6f6b 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -279,9 +279,6 @@ public static function parse(Parser $parser, TokensList $list, array $options = } } elseif (! self::checkIfTokenQuotedSymbol($token)) { if (! 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 find a delimiter between them - // We want to get the next non-comment and non-space token after $token // therefore, the first getNext call will start with the current $idx which's $token, // will return it and increase $idx by 1, which's not guaranteed to be non-comment @@ -292,15 +289,18 @@ public static function parse(Parser $parser, TokensList $list, array $options = $list->getNext(); $nextToken = $list->getNext(); - if ( - ($token->value !== 'SET' || - ( - $list->tokens[$currentTokenID - 1]->value !== 'CHARACTER' && - $nextToken->value !== '(' && - $nextToken->value !== 'DEFAULT' - ) - ) - ) { + if ($token->value === 'SET' && $list->tokens[$currentTokenID - 1]->value === 'CHARACTER'){ + // Reverting the changes we made in the beginning + $list->idx = $currentTokenID; + } else if ($token->value === 'SET' && $nextToken->value === '('){ + // To avoid adding the tokens between the SET() parentheses to the unknown tokens + $list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')'); + } else if ($token->value === 'SET' && $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 find a delimiter between them $parser->error( 'A new statement was found, but no delimiter between it and the previous one.', $token @@ -308,16 +308,6 @@ public static function parse(Parser $parser, TokensList $list, array $options = break; } - if ($nextToken->value === '(') { - // To avoid adding the tokens between the SET() parentheses to the unknown tokens - $list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')'); - } elseif ($nextToken->value === 'DEFAULT') { - // to avoid adding the `DEFAULT` token to the unknown tokens. - ++$list->idx; - } else { - // Reverting the changes we made in the beginning - $list->idx = $currentTokenID; - } } elseif ((array_key_exists($array_key, self::$DB_OPTIONS) || array_key_exists($array_key, self::$TABLE_OPTIONS)) && ! self::checkIfColumnDefinitionKeyword($array_key)