Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Components/SetOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$commaLastSeenAt = $token;
}
} elseif ($state === 1) {
// Reserved keywords like ON are valid values in SET statements
// (e.g. SET @@sql_log_bin = ON). Try parsing as expression first,
// and if that fails, accept reserved keywords as literal values.
$tmp = Expression::parse(
$parser,
$list,
['breakOnAlias' => true]
);
if ($tmp === null) {
if ($tmp === null && $token->type === Token::TYPE_KEYWORD && $token->value === 'ON') {
$tmp = new Expression($token->token);
} elseif ($tmp === null) {
$parser->error('Missing expression.', $token);
break;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/SetStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function setProvider(): array
['parser/parseSetVariable'],
['parser/parseSetVariable2'],
['parser/parseSetGlobalVariable'],
['parser/parseSetVariableOn'],
];
}
}
1 change: 1 addition & 0 deletions tests/data/parser/parseSetVariableOn.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SET @@sql_log_bin = ON, autocommit = OFF
192 changes: 192 additions & 0 deletions tests/data/parser/parseSetVariableOn.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"query": "SET @@sql_log_bin = ON, autocommit = OFF",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"str": "SET @@sql_log_bin = ON, autocommit = OFF",
"len": 40,
"last": 40,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SET",
"value": "SET",
"keyword": "SET",
"type": 1,
"flags": 11,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 3
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "@@sql_log_bin",
"value": "sql_log_bin",
"keyword": null,
"type": 8,
"flags": 9,
"position": 4
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 17
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "=",
"value": "=",
"keyword": null,
"type": 2,
"flags": 2,
"position": 18
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 19
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "ON",
"value": "ON",
"keyword": "ON",
"type": 1,
"flags": 3,
"position": 20
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ",",
"value": ",",
"keyword": null,
"type": 2,
"flags": 16,
"position": 22
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 23
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "autocommit",
"value": "autocommit",
"keyword": null,
"type": 0,
"flags": 0,
"position": 24
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 34
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "=",
"value": "=",
"keyword": null,
"type": 2,
"flags": 2,
"position": 35
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 36
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "OFF",
"value": "OFF",
"keyword": null,
"type": 0,
"flags": 0,
"position": 37
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": null,
"value": null,
"keyword": null,
"type": 9,
"flags": 0,
"position": null
}
],
"count": 15,
"idx": 15
},
"delimiter": ";",
"delimiterLen": 1,
"strict": false,
"errors": []
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\SetStatement",
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": []
},
"end_options": null,
"set": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation",
"column": "@@sql_log_bin",
"value": "ON"
},
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation",
"column": "autocommit",
"value": "OFF"
}
],
"first": 0,
"last": 13
}
],
"brackets": 0,
"strict": false,
"errors": []
},
"errors": {
"lexer": [],
"parser": []
}
}
Loading