Skip to content

Commit

Permalink
Fix using ? as a parameter
Browse files Browse the repository at this point in the history
- Fixes phpmyadmin#202
- Fixes phpmyadmin#412
- Fixes phpmyadmin#492
- Closes phpmyadmin#499
- Related to phpmyadmin#172

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Sep 26, 2023
1 parent ec459f7 commit 74504c5
Show file tree
Hide file tree
Showing 12 changed files with 1,607 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
&& (($token->type !== Token::TYPE_KEYWORD)
|| ($token->flags & Token::FLAG_KEYWORD_RESERVED))
&& ($token->type !== Token::TYPE_STRING)
&& ($token->type !== Token::TYPE_SYMBOL)
&& ($token->type !== Token::TYPE_SYMBOL || ($token->flags & Token::FLAG_SYMBOL_PARAMETER))
) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
|| ! ($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED))))
&& (($prev[1]->type === Token::TYPE_STRING)
|| ($prev[1]->type === Token::TYPE_SYMBOL
&& ! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE))
&& ! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE)
&& ! ($prev[1]->flags & Token::FLAG_SYMBOL_PARAMETER))
|| ($prev[1]->type === Token::TYPE_NONE
&& $prev[1]->token !== 'OVER'))
) {
Expand Down
1 change: 1 addition & 0 deletions tests/data/bugs/gh202.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update tbl_customer t set t.`description`=:yp where t.id=1;
284 changes: 284 additions & 0 deletions tests/data/bugs/gh202.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
{
"query": "update tbl_customer t set t.`description`=:yp where t.id=1;",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"str": "update tbl_customer t set t.`description`=:yp where t.id=1;",
"len": 59,
"last": 59,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "update",
"value": "UPDATE",
"keyword": "UPDATE",
"type": 1,
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 6
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "tbl_customer",
"value": "tbl_customer",
"keyword": null,
"type": 0,
"flags": 0,
"position": 7
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 19
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "t",
"value": "t",
"keyword": null,
"type": 0,
"flags": 0,
"position": 20
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 21
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "set",
"value": "SET",
"keyword": "SET",
"type": 1,
"flags": 11,
"position": 22
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 25
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "t",
"value": "t",
"keyword": null,
"type": 0,
"flags": 0,
"position": 26
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ".",
"value": ".",
"keyword": null,
"type": 2,
"flags": 16,
"position": 27
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`description`",
"value": "description",
"keyword": null,
"type": 8,
"flags": 2,
"position": 28
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "=",
"value": "=",
"keyword": null,
"type": 2,
"flags": 2,
"position": 41
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ":yp",
"value": "yp",
"keyword": null,
"type": 8,
"flags": 16,
"position": 42
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 45
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "where",
"value": "WHERE",
"keyword": "WHERE",
"type": 1,
"flags": 3,
"position": 46
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 51
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "t",
"value": "t",
"keyword": null,
"type": 0,
"flags": 0,
"position": 52
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ".",
"value": ".",
"keyword": null,
"type": 2,
"flags": 16,
"position": 53
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "id",
"value": "id",
"keyword": null,
"type": 0,
"flags": 0,
"position": 54
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "=",
"value": "=",
"keyword": null,
"type": 2,
"flags": 2,
"position": 56
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 57
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ";",
"value": ";",
"keyword": null,
"type": 9,
"flags": 0,
"position": 58
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": null,
"value": null,
"keyword": null,
"type": 9,
"flags": 0,
"position": null
}
],
"count": 23,
"idx": 23
},
"delimiter": ";",
"delimiterLen": 1,
"strict": false,
"errors": []
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\UpdateStatement",
"tables": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": "tbl_customer",
"column": null,
"expr": "tbl_customer",
"alias": "t",
"function": null,
"subquery": null
}
],
"set": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation",
"column": "t.`description`",
"value": ":yp"
}
],
"where": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\Condition",
"identifiers": [
"t",
"id"
],
"isOperator": false,
"expr": "t.id=1"
}
],
"order": null,
"limit": null,
"join": null,
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": []
},
"first": 0,
"last": 20
}
],
"brackets": 0,
"strict": false,
"errors": []
},
"errors": {
"lexer": [],
"parser": []
}
}
1 change: 1 addition & 0 deletions tests/data/bugs/gh412.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 1, 2, ?, 3
Loading

0 comments on commit 74504c5

Please sign in to comment.