Skip to content

Commit

Permalink
Merge pull request #581 from niconoe-/fix/580
Browse files Browse the repository at this point in the history
Proposal for a fix of #580.

Fixes #580
  • Loading branch information
MauricioFauth authored Sep 19, 2024
2 parents 91d980a + 34c7539 commit a1c555a
Show file tree
Hide file tree
Showing 9 changed files with 688 additions and 34 deletions.
5 changes: 4 additions & 1 deletion src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ class AlterOperation extends Component
'BY' => 2,
'FOREIGN' => 2,
'FULLTEXT' => 2,
'KEY' => 2,
'KEY' => [
2,
'var',
],
'KEYS' => 2,
'PARTITION' => 2,
'PARTITION BY' => 2,
Expand Down
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
18 changes: 7 additions & 11 deletions tests/data/bugs/gh317.out
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,15 @@
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": {
"1": "ADD",
"2": "KEY"
"2": {
"name": "KEY",
"equals": false,
"expr": "`IDX_REPAIR`",
"value": "IDX_REPAIR"
}
}
},
"field": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": null,
"column": "IDX_REPAIR",
"expr": "`IDX_REPAIR`",
"alias": null,
"function": null,
"subquery": null
},
"field": null,
"partitions": null,
"unknown": [
{
Expand Down
18 changes: 7 additions & 11 deletions tests/data/parser/parseAlter.out
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,15 @@
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": {
"1": "ADD",
"2": "KEY"
"2": {
"name": "KEY",
"equals": false,
"expr": "`idx_actor_last_name`",
"value": "idx_actor_last_name"
}
}
},
"field": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": null,
"column": "idx_actor_last_name",
"expr": "`idx_actor_last_name`",
"alias": null,
"function": null,
"subquery": null
},
"field": null,
"partitions": null,
"unknown": [
{
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 a1c555a

Please sign in to comment.