Skip to content

Commit

Permalink
Add test cases of the parser with ALTER TABLE … RENAME KEY … TO …
Browse files Browse the repository at this point in the history
  • Loading branch information
niconoe- committed Sep 4, 2024
1 parent 0774027 commit 34c7539
Show file tree
Hide file tree
Showing 5 changed files with 663 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/Parser/AlterStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static function alterProvider(): array
['parser/parseAlterErr4'],
['parser/parseAlterTableRenameIndex1'],
['parser/parseAlterTableRenameIndex2'],
['parser/parseAlterTableRenameKey1'],
['parser/parseAlterTableRenameKey2'],
['parser/parseAlterTablePartitionByRange1'],
['parser/parseAlterTablePartitionByRange2'],
['parser/parseAlterTableCoalescePartition'],
Expand Down
1 change: 1 addition & 0 deletions tests/data/parser/parseAlterTableRenameKey1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `transactions` RENAME KEY `fk_transactions_catalog_entries1_idx` TO `fk_transactions_catalog_entries2_idx`
249 changes: 249 additions & 0 deletions tests/data/parser/parseAlterTableRenameKey1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"query": "ALTER TABLE `transactions` RENAME KEY `fk_transactions_catalog_entries1_idx` TO `fk_transactions_catalog_entries2_idx`\n",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"str": "ALTER TABLE `transactions` RENAME KEY `fk_transactions_catalog_entries1_idx` TO `fk_transactions_catalog_entries2_idx`\n",
"len": 119,
"last": 119,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "ALTER",
"value": "ALTER",
"keyword": "ALTER",
"type": 1,
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 5
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "TABLE",
"value": "TABLE",
"keyword": "TABLE",
"type": 1,
"flags": 3,
"position": 6
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`transactions`",
"value": "transactions",
"keyword": null,
"type": 8,
"flags": 2,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 26
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "RENAME",
"value": "RENAME",
"keyword": "RENAME",
"type": 1,
"flags": 3,
"position": 27
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 33
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "KEY",
"value": "KEY",
"keyword": "KEY",
"type": 1,
"flags": 19,
"position": 34
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 37
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`fk_transactions_catalog_entries1_idx`",
"value": "fk_transactions_catalog_entries1_idx",
"keyword": null,
"type": 8,
"flags": 2,
"position": 38
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 76
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "TO",
"value": "TO",
"keyword": "TO",
"type": 1,
"flags": 3,
"position": 77
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 79
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`fk_transactions_catalog_entries2_idx`",
"value": "fk_transactions_catalog_entries2_idx",
"keyword": null,
"type": 8,
"flags": 2,
"position": 80
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 118
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": null,
"value": null,
"keyword": null,
"type": 9,
"flags": 0,
"position": null
}
],
"count": 17,
"idx": 17
},
"delimiter": ";",
"delimiterLen": 1,
"strict": false,
"errors": []
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\AlterStatement",
"table": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": "transactions",
"column": null,
"expr": "`transactions`",
"alias": null,
"function": null,
"subquery": null
},
"altered": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
"ROUTINE_OPTIONS": {
"COMMENT": [
1,
"var"
],
"LANGUAGE SQL": 2,
"CONTAINS SQL": 3,
"NO SQL": 3,
"READS SQL DATA": 3,
"MODIFIES SQL DATA": 3,
"SQL SECURITY": 4,
"DEFINER": 5,
"INVOKER": 5
},
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": {
"1": "RENAME",
"2": {
"name": "KEY",
"equals": false,
"expr": "`fk_transactions_catalog_entries1_idx`",
"value": "fk_transactions_catalog_entries1_idx"
},
"3": {
"name": "TO",
"equals": false,
"expr": "`fk_transactions_catalog_entries2_idx`",
"value": "fk_transactions_catalog_entries2_idx"
}
}
},
"field": null,
"partitions": null,
"unknown": []
}
],
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": {
"3": "TABLE"
}
},
"first": 0,
"last": 16
}
],
"brackets": 0,
"strict": false,
"errors": []
},
"errors": {
"lexer": [],
"parser": []
}
}
1 change: 1 addition & 0 deletions tests/data/parser/parseAlterTableRenameKey2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE testtable RENAME KEY my_index TO my_index2, ALGORITHM=INPLACE, LOCK=NONE;
Loading

0 comments on commit 34c7539

Please sign in to comment.