Skip to content

Commit

Permalink
Merge branch 'QA'
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Aug 16, 2021
2 parents c70841c + a724b5d commit 36b8bd8
Show file tree
Hide file tree
Showing 28 changed files with 309 additions and 774 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -73,6 +73,7 @@

- Fixed BufferedQuery when it has an odd number of backslashes in the end (#340)
- Fixed the issue that ignored the body tokens when creating views with union (#343)
- Fixed parser errors on "ALTER TABLE" statements to add columns with SET type (#168)

## [4.7.2] - 2021-02-05

Expand Down
31 changes: 27 additions & 4 deletions src/Components/AlterOperation.php
Expand Up @@ -92,9 +92,11 @@ class AlterOperation extends Component
'ALTER' => 1,
'ANALYZE' => 1,
'CHANGE' => 1,
'CHARSET' => 1,
'CHECK' => 1,
'COALESCE' => 1,
'CONVERT' => 1,
'DEFAULT CHARSET' => 1,
'DISABLE' => 1,
'DISCARD' => 1,
'DROP' => 1,
Expand Down Expand Up @@ -125,6 +127,8 @@ class AlterOperation extends Component
'SPATIAL' => 2,
'TABLESPACE' => 2,
'INDEX' => 2,

'CHARACTER SET' => 3,
];

/**
Expand Down Expand Up @@ -282,16 +286,35 @@ 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

if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
// 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
// and non-space, that's why we're calling getNext again.
// In order to get back to the original value of idx, we kept it in $currentID

$currentTokenID = $list->idx;
$list->getNext();
$nextToken = $list->getNext();

if ($token->value === 'CHARACTER SET') {
// 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
);
break;
}

} elseif (
(array_key_exists($arrayKey, self::$DB_OPTIONS)
|| array_key_exists($arrayKey, self::$TABLE_OPTIONS))
Expand Down
10 changes: 8 additions & 2 deletions tests/data/parser/parseAlter.out
Expand Up @@ -654,9 +654,11 @@
"ALTER": 1,
"ANALYZE": 1,
"CHANGE": 1,
"CHARSET": 1,
"CHECK": 1,
"COALESCE": 1,
"CONVERT": 1,
"DEFAULT CHARSET": 1,
"DISABLE": 1,
"DISCARD": 1,
"DROP": 1,
Expand Down Expand Up @@ -685,7 +687,8 @@
"PRIMARY KEY": 2,
"SPATIAL": 2,
"TABLESPACE": 2,
"INDEX": 2
"INDEX": 2,
"CHARACTER SET": 3
},
"VIEW_OPTIONS": {
"AS": 1
Expand Down Expand Up @@ -771,9 +774,11 @@
"ALTER": 1,
"ANALYZE": 1,
"CHANGE": 1,
"CHARSET": 1,
"CHECK": 1,
"COALESCE": 1,
"CONVERT": 1,
"DEFAULT CHARSET": 1,
"DISABLE": 1,
"DISCARD": 1,
"DROP": 1,
Expand Down Expand Up @@ -802,7 +807,8 @@
"PRIMARY KEY": 2,
"SPATIAL": 2,
"TABLESPACE": 2,
"INDEX": 2
"INDEX": 2,
"CHARACTER SET": 3
},
"VIEW_OPTIONS": {
"AS": 1
Expand Down
5 changes: 4 additions & 1 deletion tests/data/parser/parseAlter10.out
Expand Up @@ -618,9 +618,11 @@
"ALTER": 1,
"ANALYZE": 1,
"CHANGE": 1,
"CHARSET": 1,
"CHECK": 1,
"COALESCE": 1,
"CONVERT": 1,
"DEFAULT CHARSET": 1,
"DISABLE": 1,
"DISCARD": 1,
"DROP": 1,
Expand Down Expand Up @@ -649,7 +651,8 @@
"PRIMARY KEY": 2,
"SPATIAL": 2,
"TABLESPACE": 2,
"INDEX": 2
"INDEX": 2,
"CHARACTER SET": 3
},
"VIEW_OPTIONS": {
"AS": 1
Expand Down

0 comments on commit 36b8bd8

Please sign in to comment.