Repository navigation
Conversation
`INSERT INTO a (b) (SELECT 1)` failed with "Unexpected token." because the INSERT parser only accepted a keyword after the column list. An opening bracket there is now counted like the brackets around a top-level statement, so the SELECT parser consumes the closing one. Signed-off-by: Michał Fox <me@dualfroz.com>
| } elseif ($state === 1) { | ||
| // The `SELECT` might be wrapped in brackets, the closing one is | ||
| // handled by the statement through the bracket counter. | ||
| if ($token->type === TokenType::Operator && $token->value === '(') { |
There was a problem hiding this comment.
After this bracket every branch below is still open, not only SELECT. So some broken queries now parse with no error, where master reported one:
| query | master | this PR |
|---|---|---|
INSERT INTO a (b) (SET b=1) |
Unexpected token. |
no errors, $parser->brackets left at 1 |
INSERT INTO a (b) (SET b=1); SELECT 1 ) |
Unexpected token. |
no errors (the leftover bracket also hides the stray ) in the next statement) |
INSERT INTO a (b) ( |
Unexpected token. |
no errors |
SET and VALUES never look at $parser->brackets; only Statement::parse (so SELECT) takes the closing one back.
Letting only SELECT follow the bracket fixes the two SET rows, and the suite still passes (1032 tests):
++$parser->brackets;
++$openBrackets; // = 0 before the loop
continue;
}
if ($openBrackets > 0 && $token->keyword !== 'SELECT') {
$parser->error('Unexpected token.', $token);
break;
}The unclosed ( at the end still needs its own check after the loop.
Also, REPLACE INTO a (b) (SELECT 1) has the same error as #484 and is valid in MySQL too. ReplaceStatement has the same keyword check, so it may be worth doing it here as well.
There was a problem hiding this comment.
good catch, thanks. only SELECT can follow the bracket now, anything else (and the unclosed one) errors at the bracket like on master, with the counter put back. did REPLACE too and added fixtures for all of these
Anything other than SELECT after the opening bracket, or a bracket left unclosed, now fails the same way as before, with the bracket counter restored. REPLACE INTO a (b) (SELECT ...) is parsed the same way. Signed-off-by: Michał Fox <me@dualfroz.com>
the INSERT parser expected a keyword right after the column list, so
INSERT INTO A (b) (SELECT 1)ended with "Unexpected token." and the select got split off into a second statement. an opening bracket there now goes into$parser->bracketsthe same way as brackets around a top-level statement, so the select should pick up the closing one itself. added a fixture for it. Fixes #484