diff --git a/src/Components/Condition.php b/src/Components/Condition.php index 2948fcdd5..987e6b162 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -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; } diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 980f59724..57037ec98 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -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')) ) { diff --git a/src/Lexer.php b/src/Lexer.php index 73b5aa060..e8586b88f 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -1049,7 +1049,7 @@ public function parseSymbol() if ($str === null) { $str = $this->parseUnknown(); - if ($str === null) { + if ($str === null && ! ($flags & Token::FLAG_SYMBOL_PARAMETER)) { $this->error('Variable name was expected.', $this->str[$this->last], $this->last); } } diff --git a/tests/Misc/BugsTest.php b/tests/Misc/BugsTest.php index d8da5fd46..88606d867 100644 --- a/tests/Misc/BugsTest.php +++ b/tests/Misc/BugsTest.php @@ -29,9 +29,13 @@ public function bugProvider(): array ['bugs/gh9'], ['bugs/gh14'], ['bugs/gh16'], + ['bugs/gh202'], ['bugs/gh234'], ['bugs/gh317'], + ['bugs/gh412'], ['bugs/gh478'], + ['bugs/gh492'], + ['bugs/gh499'], ['bugs/gh508'], ['bugs/gh511'], ['bugs/pma11800'], diff --git a/tests/Misc/ParameterTest.php b/tests/Misc/ParameterTest.php index 3724e2a79..7db96b0bc 100644 --- a/tests/Misc/ParameterTest.php +++ b/tests/Misc/ParameterTest.php @@ -23,6 +23,7 @@ public function parameterProvider(): array { return [ ['misc/parseParameter'], + ['misc/parseParameter2'], ]; } } diff --git a/tests/data/bugs/gh202.in b/tests/data/bugs/gh202.in new file mode 100644 index 000000000..0a8e86066 --- /dev/null +++ b/tests/data/bugs/gh202.in @@ -0,0 +1 @@ +update tbl_customer t set t.`description`=:yp where t.id=1; \ No newline at end of file diff --git a/tests/data/bugs/gh202.out b/tests/data/bugs/gh202.out new file mode 100644 index 000000000..942280786 --- /dev/null +++ b/tests/data/bugs/gh202.out @@ -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": [] + } +} \ No newline at end of file diff --git a/tests/data/bugs/gh412.in b/tests/data/bugs/gh412.in new file mode 100644 index 000000000..513a1deeb --- /dev/null +++ b/tests/data/bugs/gh412.in @@ -0,0 +1 @@ +SELECT 1, 2, ?, 3 \ No newline at end of file diff --git a/tests/data/bugs/gh412.out b/tests/data/bugs/gh412.out new file mode 100644 index 000000000..9f47182c2 --- /dev/null +++ b/tests/data/bugs/gh412.out @@ -0,0 +1,217 @@ +{ + "query": "SELECT 1, 2, ?, 3", + "lexer": { + "@type": "PhpMyAdmin\\SqlParser\\Lexer", + "str": "SELECT 1, 2, ?, 3", + "len": 17, + "last": 17, + "list": { + "@type": "PhpMyAdmin\\SqlParser\\TokensList", + "tokens": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "SELECT", + "value": "SELECT", + "keyword": "SELECT", + "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": "1", + "value": 1, + "keyword": null, + "type": 6, + "flags": 0, + "position": 7 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 8 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 9 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "2", + "value": 2, + "keyword": null, + "type": 6, + "flags": 0, + "position": 10 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 11 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 12 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 13 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 14 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 15 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "3", + "value": 3, + "keyword": null, + "type": 6, + "flags": 0, + "position": 16 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": null, + "value": null, + "keyword": null, + "type": 9, + "flags": 0, + "position": null + } + ], + "count": 13, + "idx": 13 + }, + "delimiter": ";", + "delimiterLen": 1, + "strict": false, + "errors": [] + }, + "parser": { + "@type": "PhpMyAdmin\\SqlParser\\Parser", + "list": { + "@type": "@1" + }, + "statements": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Statements\\SelectStatement", + "expr": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": null, + "column": null, + "expr": "1", + "alias": null, + "function": null, + "subquery": null + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": null, + "column": null, + "expr": "2", + "alias": null, + "function": null, + "subquery": null + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": null, + "column": null, + "expr": "?", + "alias": null, + "function": null, + "subquery": null + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": null, + "column": null, + "expr": "3", + "alias": null, + "function": null, + "subquery": null + } + ], + "from": [], + "index_hints": null, + "partition": null, + "where": null, + "group": null, + "group_options": null, + "having": null, + "order": null, + "limit": null, + "procedure": null, + "into": null, + "join": null, + "union": [], + "end_options": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + }, + "first": 0, + "last": 11 + } + ], + "brackets": 0, + "strict": false, + "errors": [] + }, + "errors": { + "lexer": [], + "parser": [] + } +} \ No newline at end of file diff --git a/tests/data/bugs/gh492.in b/tests/data/bugs/gh492.in new file mode 100644 index 000000000..33e397764 --- /dev/null +++ b/tests/data/bugs/gh492.in @@ -0,0 +1,3 @@ +UPDATE order +SET price = ? +WHERE orderid = ? \ No newline at end of file diff --git a/tests/data/bugs/gh492.out b/tests/data/bugs/gh492.out new file mode 100644 index 000000000..785585f4a --- /dev/null +++ b/tests/data/bugs/gh492.out @@ -0,0 +1,260 @@ +{ + "query": "UPDATE order\nSET price = ?\nWHERE orderid = ?", + "lexer": { + "@type": "PhpMyAdmin\\SqlParser\\Lexer", + "str": "UPDATE order\nSET price = ?\nWHERE orderid = ?", + "len": 51, + "last": 51, + "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": "order", + "value": "ORDER", + "keyword": "ORDER", + "type": 1, + "flags": 3, + "position": 8 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 13 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "SET", + "value": "SET", + "keyword": "SET", + "type": 1, + "flags": 11, + "position": 14 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 17 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "price", + "value": "price", + "keyword": null, + "type": 0, + "flags": 0, + "position": 22 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 27 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "=", + "value": "=", + "keyword": null, + "type": 2, + "flags": 2, + "position": 28 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 29 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 30 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 31 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "WHERE", + "value": "WHERE", + "keyword": "WHERE", + "type": 1, + "flags": 3, + "position": 32 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 37 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "orderid", + "value": "orderid", + "keyword": null, + "type": 0, + "flags": 0, + "position": 40 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 47 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "=", + "value": "=", + "keyword": null, + "type": 2, + "flags": 2, + "position": 48 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 49 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 50 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": null, + "value": null, + "keyword": null, + "type": 9, + "flags": 0, + "position": null + } + ], + "count": 20, + "idx": 20 + }, + "delimiter": ";", + "delimiterLen": 1, + "strict": false, + "errors": [] + }, + "parser": { + "@type": "PhpMyAdmin\\SqlParser\\Parser", + "list": { + "@type": "@1" + }, + "statements": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Statements\\UpdateStatement", + "tables": [], + "set": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation", + "column": "price", + "value": "?" + } + ], + "where": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Condition", + "identifiers": [ + "orderid" + ], + "isOperator": false, + "expr": "orderid = ?" + } + ], + "order": null, + "limit": null, + "join": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + }, + "first": 0, + "last": 18 + } + ], + "brackets": 0, + "strict": false, + "errors": [] + }, + "errors": { + "lexer": [], + "parser": [ + [ + "An expression was expected.", + { + "@type": "@4" + }, + 0 + ], + [ + "Unrecognized keyword.", + { + "@type": "@4" + }, + 0 + ] + ] + } +} \ No newline at end of file diff --git a/tests/data/bugs/gh499.in b/tests/data/bugs/gh499.in new file mode 100644 index 000000000..ff1582c96 --- /dev/null +++ b/tests/data/bugs/gh499.in @@ -0,0 +1,11 @@ +UPDATE + users +SET + username = ?, + id=155; + +UPDATE + users +SET + username = :user_name, + id=155; \ No newline at end of file diff --git a/tests/data/bugs/gh499.out b/tests/data/bugs/gh499.out new file mode 100644 index 000000000..b0b2715bf --- /dev/null +++ b/tests/data/bugs/gh499.out @@ -0,0 +1,433 @@ +{ + "query": "UPDATE\n users\nSET\n username = ?,\n id=155;\n\nUPDATE\n users\nSET\n username = :user_name,\n id=155;", + "lexer": { + "@type": "PhpMyAdmin\\SqlParser\\Lexer", + "str": "UPDATE\n users\nSET\n username = ?,\n id=155;\n\nUPDATE\n users\nSET\n username = :user_name,\n id=155;", + "len": 111, + "last": 111, + "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": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 6 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "users", + "value": "users", + "keyword": null, + "type": 0, + "flags": 0, + "position": 11 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 16 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "SET", + "value": "SET", + "keyword": "SET", + "type": 1, + "flags": 11, + "position": 17 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 20 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "username", + "value": "username", + "keyword": null, + "type": 0, + "flags": 0, + "position": 25 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 33 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "=", + "value": "=", + "keyword": null, + "type": 2, + "flags": 2, + "position": 34 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 35 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 36 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 37 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 38 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "id", + "value": "id", + "keyword": null, + "type": 0, + "flags": 0, + "position": 43 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "=", + "value": "=", + "keyword": null, + "type": 2, + "flags": 2, + "position": 45 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "155", + "value": 155, + "keyword": null, + "type": 6, + "flags": 0, + "position": 46 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ";", + "value": ";", + "keyword": null, + "type": 9, + "flags": 0, + "position": 49 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 50 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "UPDATE", + "value": "UPDATE", + "keyword": "UPDATE", + "type": 1, + "flags": 3, + "position": 52 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 58 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "users", + "value": "users", + "keyword": null, + "type": 0, + "flags": 0, + "position": 63 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 68 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "SET", + "value": "SET", + "keyword": "SET", + "type": 1, + "flags": 11, + "position": 69 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 72 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "username", + "value": "username", + "keyword": null, + "type": 0, + "flags": 0, + "position": 77 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 85 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "=", + "value": "=", + "keyword": null, + "type": 2, + "flags": 2, + "position": 86 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 87 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ":user_name", + "value": "user_name", + "keyword": null, + "type": 8, + "flags": 16, + "position": 88 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 98 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 99 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "id", + "value": "id", + "keyword": null, + "type": 0, + "flags": 0, + "position": 104 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "=", + "value": "=", + "keyword": null, + "type": 2, + "flags": 2, + "position": 106 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "155", + "value": 155, + "keyword": null, + "type": 6, + "flags": 0, + "position": 107 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ";", + "value": ";", + "keyword": null, + "type": 9, + "flags": 0, + "position": 110 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": null, + "value": null, + "keyword": null, + "type": 9, + "flags": 0, + "position": null + } + ], + "count": 36, + "idx": 36 + }, + "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": "users", + "column": null, + "expr": "users", + "alias": null, + "function": null, + "subquery": null + } + ], + "set": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation", + "column": "username", + "value": "?" + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation", + "column": "id", + "value": "155" + } + ], + "where": null, + "order": null, + "limit": null, + "join": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + }, + "first": 0, + "last": 15 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Statements\\UpdateStatement", + "tables": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": "users", + "column": null, + "expr": "users", + "alias": null, + "function": null, + "subquery": null + } + ], + "set": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation", + "column": "username", + "value": ":user_name" + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation", + "column": "id", + "value": "155" + } + ], + "where": null, + "order": null, + "limit": null, + "join": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + }, + "first": 16, + "last": 33 + } + ], + "brackets": 0, + "strict": false, + "errors": [] + }, + "errors": { + "lexer": [], + "parser": [] + } +} \ No newline at end of file diff --git a/tests/data/misc/parseParameter2.in b/tests/data/misc/parseParameter2.in new file mode 100644 index 000000000..09efa6b03 --- /dev/null +++ b/tests/data/misc/parseParameter2.in @@ -0,0 +1 @@ +INSERT INTO `person` (`firstname`, `lastname`, `email`) VALUES (?, ?, ?); \ No newline at end of file diff --git a/tests/data/misc/parseParameter2.out b/tests/data/misc/parseParameter2.out new file mode 100644 index 000000000..eaf30993a --- /dev/null +++ b/tests/data/misc/parseParameter2.out @@ -0,0 +1,347 @@ +{ + "query": "INSERT INTO `person` (`firstname`, `lastname`, `email`) VALUES (?, ?, ?);", + "lexer": { + "@type": "PhpMyAdmin\\SqlParser\\Lexer", + "str": "INSERT INTO `person` (`firstname`, `lastname`, `email`) VALUES (?, ?, ?);", + "len": 73, + "last": 73, + "list": { + "@type": "PhpMyAdmin\\SqlParser\\TokensList", + "tokens": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "INSERT", + "value": "INSERT", + "keyword": "INSERT", + "type": 1, + "flags": 35, + "position": 0 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 6 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "INTO", + "value": "INTO", + "keyword": "INTO", + "type": 1, + "flags": 3, + "position": 7 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 11 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`person`", + "value": "person", + "keyword": null, + "type": 8, + "flags": 2, + "position": 12 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 20 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 21 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`firstname`", + "value": "firstname", + "keyword": null, + "type": 8, + "flags": 2, + "position": 22 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 33 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 34 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`lastname`", + "value": "lastname", + "keyword": null, + "type": 8, + "flags": 2, + "position": 35 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 45 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 46 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`email`", + "value": "email", + "keyword": null, + "type": 8, + "flags": 2, + "position": 47 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 54 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 55 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "VALUES", + "value": "VALUES", + "keyword": "VALUES", + "type": 1, + "flags": 35, + "position": 56 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 62 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 63 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 64 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 65 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 66 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 67 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 68 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 69 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "?", + "value": "?", + "keyword": null, + "type": 8, + "flags": 16, + "position": 70 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 71 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ";", + "value": ";", + "keyword": null, + "type": 9, + "flags": 0, + "position": 72 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": null, + "value": null, + "keyword": null, + "type": 9, + "flags": 0, + "position": null + } + ], + "count": 29, + "idx": 29 + }, + "delimiter": ";", + "delimiterLen": 1, + "strict": false, + "errors": [] + }, + "parser": { + "@type": "PhpMyAdmin\\SqlParser\\Parser", + "list": { + "@type": "@1" + }, + "statements": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Statements\\InsertStatement", + "into": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\IntoKeyword", + "type": null, + "dest": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": "person", + "column": null, + "expr": "`person`", + "alias": null, + "function": null, + "subquery": null + }, + "columns": [ + "firstname", + "lastname", + "email" + ], + "values": null, + "fields_options": null, + "fields_keyword": null, + "lines_options": null + }, + "values": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\ArrayObj", + "raw": [ + "?", + "?", + "?" + ], + "values": [ + "?", + "?", + "?" + ] + } + ], + "set": null, + "select": null, + "with": null, + "onDuplicateSet": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + }, + "first": 0, + "last": 26 + } + ], + "brackets": 0, + "strict": false, + "errors": [] + }, + "errors": { + "lexer": [], + "parser": [] + } +} \ No newline at end of file