From 31dc0c63d2ae8ccf609ccc2cd81fc96e88b3374f Mon Sep 17 00:00:00 2001 From: Nicolas Giraud Date: Mon, 26 Aug 2024 14:20:24 +0200 Subject: [PATCH] Add test case with the WITH PARSER expression, with errors in parsing. --- tests/Parser/CreateStatementTest.php | 1 + .../data/parser/parseCreateTableWithParser.in | 5 + .../parser/parseCreateTableWithParser.out | 760 ++++++++++++++++++ 3 files changed, 766 insertions(+) create mode 100644 tests/data/parser/parseCreateTableWithParser.in create mode 100644 tests/data/parser/parseCreateTableWithParser.out diff --git a/tests/Parser/CreateStatementTest.php b/tests/Parser/CreateStatementTest.php index 1cdd86f38..5c4ad0573 100644 --- a/tests/Parser/CreateStatementTest.php +++ b/tests/Parser/CreateStatementTest.php @@ -66,6 +66,7 @@ public static function createProvider(): array ['parser/parseCreateTableEnforcedCheck'], ['parser/parseCreateTableNotEnforcedCheck'], ['parser/parseCreateTableWithInvisibleKey'], + ['parser/parseCreateTableWithParser'], ['parser/parseCreateTrigger'], ['parser/parseCreateUser1'], ['parser/parseCreateUser2'], diff --git a/tests/data/parser/parseCreateTableWithParser.in b/tests/data/parser/parseCreateTableWithParser.in new file mode 100644 index 000000000..3613b4406 --- /dev/null +++ b/tests/data/parser/parseCreateTableWithParser.in @@ -0,0 +1,5 @@ +CREATE TABLE `mytable` ( + `column_one` smallint unsigned DEFAULT NULL, + FULLTEXT KEY `fulltext_index` (`column_one`) /*!50100 WITH PARSER `ngram` */, + CONSTRAINT `my_constraint_1` FOREIGN KEY (`column_one`) REFERENCES `other_table` (`column_two`) ON DELETE RESTRICT ON UPDATE RESTRICT +) diff --git a/tests/data/parser/parseCreateTableWithParser.out b/tests/data/parser/parseCreateTableWithParser.out new file mode 100644 index 000000000..c0d3b0354 --- /dev/null +++ b/tests/data/parser/parseCreateTableWithParser.out @@ -0,0 +1,760 @@ +{ + "query": "CREATE TABLE `mytable` (\n `column_one` smallint unsigned DEFAULT NULL,\n FULLTEXT KEY `fulltext_index` (`column_one`) /*!50100 WITH PARSER `ngram` */,\n CONSTRAINT `my_constraint_1` FOREIGN KEY (`column_one`) REFERENCES `other_table` (`column_two`) ON DELETE RESTRICT ON UPDATE RESTRICT\n)\n", + "lexer": { + "@type": "PhpMyAdmin\\SqlParser\\Lexer", + "str": "CREATE TABLE `mytable` (\n `column_one` smallint unsigned DEFAULT NULL,\n FULLTEXT KEY `fulltext_index` (`column_one`) /*!50100 WITH PARSER `ngram` */,\n CONSTRAINT `my_constraint_1` FOREIGN KEY (`column_one`) REFERENCES `other_table` (`column_two`) ON DELETE RESTRICT ON UPDATE RESTRICT\n)\n", + "len": 290, + "last": 290, + "list": { + "@type": "PhpMyAdmin\\SqlParser\\TokensList", + "tokens": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "CREATE", + "value": "CREATE", + "keyword": "CREATE", + "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": "TABLE", + "value": "TABLE", + "keyword": "TABLE", + "type": 1, + "flags": 3, + "position": 7 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 12 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`mytable`", + "value": "mytable", + "keyword": null, + "type": 8, + "flags": 2, + "position": 13 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 22 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 23 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 24 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`column_one`", + "value": "column_one", + "keyword": null, + "type": 8, + "flags": 2, + "position": 27 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 39 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "smallint", + "value": "SMALLINT", + "keyword": "SMALLINT", + "type": 1, + "flags": 11, + "position": 40 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 48 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "unsigned", + "value": "UNSIGNED", + "keyword": "UNSIGNED", + "type": 1, + "flags": 3, + "position": 49 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 57 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "DEFAULT", + "value": "DEFAULT", + "keyword": "DEFAULT", + "type": 1, + "flags": 35, + "position": 58 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 65 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "NULL", + "value": "NULL", + "keyword": "NULL", + "type": 1, + "flags": 3, + "position": 66 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 70 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 71 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "FULLTEXT KEY", + "value": "FULLTEXT KEY", + "keyword": "FULLTEXT KEY", + "type": 1, + "flags": 23, + "position": 74 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 86 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`fulltext_index`", + "value": "fulltext_index", + "keyword": null, + "type": 8, + "flags": 2, + "position": 87 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 103 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 104 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`column_one`", + "value": "column_one", + "keyword": null, + "type": 8, + "flags": 2, + "position": 105 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 117 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 118 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "/*!50100", + "value": "/*!50100", + "keyword": null, + "type": 4, + "flags": 10, + "position": 119 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 127 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "WITH", + "value": "WITH", + "keyword": "WITH", + "type": 1, + "flags": 3, + "position": 128 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 132 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "PARSER", + "value": "PARSER", + "keyword": "PARSER", + "type": 1, + "flags": 1, + "position": 133 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 139 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`ngram`", + "value": "ngram", + "keyword": null, + "type": 8, + "flags": 2, + "position": 140 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 147 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "*/", + "value": "*/", + "keyword": null, + "type": 4, + "flags": 2, + "position": 148 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ",", + "value": ",", + "keyword": null, + "type": 2, + "flags": 16, + "position": 150 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 151 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "CONSTRAINT", + "value": "CONSTRAINT", + "keyword": "CONSTRAINT", + "type": 1, + "flags": 3, + "position": 154 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 164 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`my_constraint_1`", + "value": "my_constraint_1", + "keyword": null, + "type": 8, + "flags": 2, + "position": 165 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 182 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "FOREIGN KEY", + "value": "FOREIGN KEY", + "keyword": "FOREIGN KEY", + "type": 1, + "flags": 23, + "position": 183 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 194 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 195 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`column_one`", + "value": "column_one", + "keyword": null, + "type": 8, + "flags": 2, + "position": 196 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 208 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 209 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "REFERENCES", + "value": "REFERENCES", + "keyword": "REFERENCES", + "type": 1, + "flags": 3, + "position": 210 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 220 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`other_table`", + "value": "other_table", + "keyword": null, + "type": 8, + "flags": 2, + "position": 221 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 234 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 235 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`column_two`", + "value": "column_two", + "keyword": null, + "type": 8, + "flags": 2, + "position": 236 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 248 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 249 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "ON DELETE", + "value": "ON DELETE", + "keyword": "ON DELETE", + "type": 1, + "flags": 7, + "position": 250 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 259 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "RESTRICT", + "value": "RESTRICT", + "keyword": "RESTRICT", + "type": 1, + "flags": 3, + "position": 260 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 268 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "ON UPDATE", + "value": "ON UPDATE", + "keyword": "ON UPDATE", + "type": 1, + "flags": 7, + "position": 269 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 278 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "RESTRICT", + "value": "RESTRICT", + "keyword": "RESTRICT", + "type": 1, + "flags": 3, + "position": 279 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 287 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 288 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "\n", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 289 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": null, + "value": null, + "keyword": null, + "type": 9, + "flags": 0, + "position": null + } + ], + "count": 67, + "idx": 68 + }, + "delimiter": ";", + "delimiterLen": 1, + "strict": false, + "errors": [] + }, + "parser": { + "@type": "PhpMyAdmin\\SqlParser\\Parser", + "list": { + "@type": "@1" + }, + "statements": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Statements\\CreateStatement", + "name": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": "mytable", + "column": null, + "expr": "`mytable`", + "alias": null, + "function": null, + "subquery": null + }, + "entityOptions": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + }, + "fields": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\CreateDefinition", + "name": "column_one", + "isConstraint": null, + "type": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\DataType", + "name": "SMALLINT", + "parameters": [], + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": { + "4": "UNSIGNED" + } + } + }, + "key": null, + "references": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": { + "2": { + "name": "DEFAULT", + "equals": false, + "expr": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": null, + "column": null, + "expr": "NULL", + "alias": null, + "function": null, + "subquery": null + }, + "value": "NULL" + } + } + } + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\CreateDefinition", + "name": null, + "isConstraint": null, + "type": null, + "key": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Key", + "name": "fulltext_index", + "columns": [ + { + "name": "column_one" + } + ], + "type": "FULLTEXT KEY", + "expr": null, + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": [] + } + }, + "references": null, + "options": null + } + ], + "with": null, + "select": null, + "like": null, + "partitionBy": null, + "partitionsNum": null, + "subpartitionBy": null, + "subpartitionsNum": null, + "partitions": null, + "table": null, + "return": null, + "parameters": null, + "body": [], + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": { + "6": "TABLE" + } + }, + "first": 0, + "last": 44 + } + ], + "brackets": 0, + "strict": false, + "errors": [] + }, + "errors": { + "lexer": [], + "parser": [ + [ + "A comma or a closing bracket was expected.", + { + "@type": "@31" + }, + 0 + ], + [ + "Unexpected beginning of statement.", + { + "@type": "@47" + }, + 0 + ], + [ + "Unrecognized statement type.", + { + "@type": "@50" + }, + 0 + ] + ] + } +} \ No newline at end of file