diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php index 104f71d9..2faf0c61 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -139,11 +139,6 @@ public static function parse(Parser $parser, TokensList $list, array $options = $parser->error('Unexpected token.', $commaLastSeenAt); } - // We got a SET operation without any assignment - if ($ret === []) { - $parser->error('Missing assignment in SET operation.', $list->tokens[$list->idx]); - } - return $ret; } diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php index d6dcdf95..acbe0b83 100644 --- a/src/Statements/UpdateStatement.php +++ b/src/Statements/UpdateStatement.php @@ -10,7 +10,11 @@ use PhpMyAdmin\SqlParser\Components\Limit; use PhpMyAdmin\SqlParser\Components\OrderKeyword; use PhpMyAdmin\SqlParser\Components\SetOperation; +use PhpMyAdmin\SqlParser\Exceptions\ParserException; +use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statement; +use PhpMyAdmin\SqlParser\Token; +use PhpMyAdmin\SqlParser\TokensList; /** * `UPDATE` statement. @@ -135,4 +139,23 @@ class UpdateStatement extends Statement * @var JoinKeyword[]|null */ public $join; + + /** + * Function called after the token was processed. + * In the update statement, this is used to check that at least one assignment has been set to throw an error if a + * query like `UPDATE acme SET WHERE 1;` is parsed. + * + * @throws ParserException + */ + public function after(Parser $parser, TokensList $list, Token $token) + { + /** @psalm-var string $tokenValue */ + $tokenValue = $token->value; + // Ensure we finished to parse the "SET" token, and if yes, ensure that assignments are defined. + if ($this->set !== [] || (Parser::$KEYWORD_PARSERS[$tokenValue]['field'] ?? null) !== 'set') { + return; + } + + $parser->error('Missing assignment in SET operation.', $list->tokens[$list->idx]); + } } diff --git a/tests/data/parser/parseUpdate3.out b/tests/data/parser/parseUpdate3.out index 33621c29..75a41bff 100644 --- a/tests/data/parser/parseUpdate3.out +++ b/tests/data/parser/parseUpdate3.out @@ -243,6 +243,13 @@ "@type": "@12" }, 0 + ], + [ + "Missing assignment in SET operation.", + { + "@type": "@11" + }, + 0 ] ] }