Skip to content

Commit

Permalink
Merge branch '5.11.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Aug 29, 2024
2 parents 4c4d552 + 91d980a commit 91d2bbf
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 4 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
- Move `Misc::getAliases()` into `SelectStatement::getAliases()` (#454)
- Drop `USE_UTF_STRINGS` constant (#471)

## [5.10.0] - YYYY-MM-DD
## [5.10.0] - 2024-08-29

- Fix parsing of UPDATE ... SET (#577)
- Fix parsing of WITH PARSER (#563)
- Fix context files for MySQL and MariaDB (#572) (#576)
- Allow using `::class` keyword to load a context (#571)
- Fix query flags for lower-case functions (#564)
- Improve context files by using constants (#570)
- Fix case when a condition is not parsed correctly (#560)
- Support parsing KILL statements (#556)
- Fix query flags for lower-case functions (#564)
- Allow using `::class` keyword to load a context (#571)
- Fix replace clause of select statement with FOR UPDATE (#555)
- Add support for ALTER FUNCTION and ALTER PROCEDURE statements (#553)

## [5.9.1] - 2024-08-13

Expand Down Expand Up @@ -580,5 +586,6 @@ __Breaking changes:__

* First release of this library.

[5.10.0]: https://github.com/phpmyadmin/sql-parser/compare/5.9.1...5.10.0
[5.9.1]: https://github.com/phpmyadmin/sql-parser/compare/5.9.0...5.9.1
[5.9.0]: https://github.com/phpmyadmin/sql-parser/compare/5.8.2...5.9.0
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ parameters:
count: 1
path: src/Tools/ContextGenerator.php

-
message: "#^Offset 1 does not exist on array\\{0\\?\\: string, 1\\?\\: non\\-empty\\-string, 2\\?\\: numeric\\-string\\}\\.$#"
count: 1
path: src/Tools/ContextGenerator.php

-
message: "#^Offset 2 does not exist on array\\{0\\?\\: string, 1\\?\\: non\\-empty\\-string, 2\\?\\: numeric\\-string\\}\\.$#"
count: 1
path: src/Tools/ContextGenerator.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, array\\<int, string\\>\\|false given\\.$#"
count: 1
Expand Down
1 change: 0 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@
<file src="src/Statements/UpdateStatement.php">
<PossiblyUnusedProperty>
<code><![CDATA[$join]]></code>
<code><![CDATA[$set]]></code>
<code><![CDATA[$where]]></code>
</PossiblyUnusedProperty>
</file>
Expand Down
23 changes: 23 additions & 0 deletions src/Statements/UpdateStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -132,4 +136,23 @@ class UpdateStatement extends Statement
* @var JoinKeyword[]|null
*/
public array|null $join = null;

/**
* 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 throws the exception, if strict mode is enabled.
*/
public function after(Parser $parser, TokensList $list, Token $token): void
{
/** @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]);
}
}
1 change: 1 addition & 0 deletions tests/Parser/UpdateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function updateProvider(): array
['parser/parseUpdate6'],
['parser/parseUpdate7'],
['parser/parseUpdateErr'],
['parser/parseUpdateEmptySet'],
];
}
}
7 changes: 7 additions & 0 deletions tests/data/parser/parseUpdate3.out
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@
"@type": "@16"
},
0
],
[
"Missing assignment in SET operation.",
{
"@type": "@15"
},
0
]
]
}
Expand Down
1 change: 1 addition & 0 deletions tests/data/parser/parseUpdateEmptySet.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE test SET WHERE 1;
221 changes: 221 additions & 0 deletions tests/data/parser/parseUpdateEmptySet.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"query": "UPDATE test SET WHERE 1;\n",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"strict": false,
"errors": [],
"str": "UPDATE test SET WHERE 1;\n",
"len": 25,
"last": 25,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"count": 12,
"idx": 12,
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "UPDATE",
"value": "UPDATE",
"keyword": "UPDATE",
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Keyword",
"value": 1
},
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Whitespace",
"value": 3
},
"flags": 0,
"position": 6
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "test",
"value": "test",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "None",
"value": 0
},
"flags": 0,
"position": 7
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SET",
"value": "SET",
"keyword": "SET",
"type": {
"@type": "@3"
},
"flags": 11,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 15
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "WHERE",
"value": "WHERE",
"keyword": "WHERE",
"type": {
"@type": "@3"
},
"flags": 3,
"position": 16
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 21
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Number",
"value": 6
},
"flags": 0,
"position": 22
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ";",
"value": ";",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Delimiter",
"value": 9
},
"flags": 0,
"position": 23
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 24
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "",
"value": "",
"keyword": null,
"type": {
"@type": "@16"
},
"flags": 0,
"position": null
}
]
},
"delimiter": ";",
"delimiterLen": 1
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"strict": false,
"errors": [],
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\UpdateStatement",
"tables": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": "test",
"column": null,
"expr": "test",
"alias": null,
"function": null,
"subquery": null
}
],
"set": [],
"where": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\Condition",
"identifiers": [],
"isOperator": false,
"expr": "1",
"leftOperand": "1",
"operator": "",
"rightOperand": ""
}
],
"order": null,
"limit": null,
"join": null,
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": []
},
"first": 0,
"last": 8
}
],
"brackets": 0
},
"errors": {
"lexer": [],
"parser": [
[
"Missing assignment in SET operation.",
{
"@type": "@10"
},
0
]
]
}
}

0 comments on commit 91d2bbf

Please sign in to comment.