@@ -92,9 +92,11 @@ class AlterOperation extends Component
9292 'ALTER ' => 1 ,
9393 'ANALYZE ' => 1 ,
9494 'CHANGE ' => 1 ,
95+ 'CHARSET ' => 1 ,
9596 'CHECK ' => 1 ,
9697 'COALESCE ' => 1 ,
9798 'CONVERT ' => 1 ,
99+ 'DEFAULT CHARSET ' => 1 ,
98100 'DISABLE ' => 1 ,
99101 'DISCARD ' => 1 ,
100102 'DROP ' => 1 ,
@@ -125,6 +127,8 @@ class AlterOperation extends Component
125127 'SPATIAL ' => 2 ,
126128 'TABLESPACE ' => 2 ,
127129 'INDEX ' => 2 ,
130+
131+ 'CHARACTER SET ' => 3 ,
128132 ];
129133
130134 /**
@@ -282,16 +286,35 @@ public static function parse(Parser $parser, TokensList $list, array $options =
282286 }
283287 } elseif (! self ::checkIfTokenQuotedSymbol ($ token )) {
284288 if (! empty (Parser::$ STATEMENT_PARSERS [$ token ->value ])) {
285- // We have reached the end of ALTER operation and suddenly found
286- // a start to new statement, but have not find a delimiter between them
287-
288- if (! ($ token ->value === 'SET ' && $ list ->tokens [$ list ->idx - 1 ]->value === 'CHARACTER ' )) {
289+ // We want to get the next non-comment and non-space token after $token
290+ // therefore, the first getNext call will start with the current $idx which's $token,
291+ // will return it and increase $idx by 1, which's not guaranteed to be non-comment
292+ // and non-space, that's why we're calling getNext again.
293+ // In order to get back to the original value of idx, we kept it in $currentID
294+
295+ $ currentTokenID = $ list ->idx ;
296+ $ list ->getNext ();
297+ $ nextToken = $ list ->getNext ();
298+
299+ if ($ token ->value === 'CHARACTER SET ' ) {
300+ // Reverting the changes we made in the beginning
301+ $ list ->idx = $ currentTokenID ;
302+ } else if ($ token ->value === 'SET ' && $ nextToken ->value === '( ' ) {
303+ // To avoid adding the tokens between the SET() parentheses to the unknown tokens
304+ $ list ->getNextOfTypeAndValue (Token::TYPE_OPERATOR , ') ' );
305+ } else if ($ token ->value === 'SET ' && $ nextToken ->value === 'DEFAULT ' ) {
306+ // to avoid adding the `DEFAULT` token to the unknown tokens.
307+ ++$ list ->idx ;
308+ } else {
309+ // We have reached the end of ALTER operation and suddenly found
310+ // a start to new statement, but have not find a delimiter between them
289311 $ parser ->error (
290312 'A new statement was found, but no delimiter between it and the previous one. ' ,
291313 $ token
292314 );
293315 break ;
294316 }
317+
295318 } elseif (
296319 (array_key_exists ($ arrayKey , self ::$ DB_OPTIONS )
297320 || array_key_exists ($ arrayKey , self ::$ TABLE_OPTIONS ))
0 commit comments