Skip to content

Commit 81c583a

Browse files
committed
Merge #408 - Fix #404 - Implement ALTER EVENT
Fixes: #404 Pull-request: #408 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents 506d4ae + 5790812 commit 81c583a

19 files changed

+1330
-751
lines changed

src/Components/AlterOperation.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,47 @@ class AlterOperation extends Component
182182
*/
183183
public static $VIEW_OPTIONS = ['AS' => 1];
184184

185+
/**
186+
* All event options.
187+
*
188+
* @var array<string, int|array<int, int|string>>
189+
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})>
190+
*/
191+
public static $EVENT_OPTIONS = [
192+
'ON SCHEDULE' => 1,
193+
'EVERY' => [
194+
2,
195+
'expr',
196+
],
197+
'AT' => [
198+
2,
199+
'expr',
200+
],
201+
'STARTS' => [
202+
3,
203+
'expr',
204+
],
205+
'ENDS' => [
206+
4,
207+
'expr',
208+
],
209+
'ON COMPLETION PRESERVE' => 5,
210+
'ON COMPLETION NOT PRESERVE' => 5,
211+
'RENAME' => 6,
212+
'TO' => [
213+
7,
214+
'var',
215+
],
216+
'ENABLE' => 8,
217+
'DISABLE' => 8,
218+
'DISABLE ON SLAVE' => 8,
219+
'COMMENT' => [
220+
9,
221+
'var',
222+
],
223+
'DO' => 10,
224+
];
225+
185226
/**
186227
* Options of this operation.
187228
*
@@ -299,7 +340,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
299340
if ($state === 0) {
300341
$ret->options = OptionsArray::parse($parser, $list, $options);
301342

302-
if ($ret->options->has('AS')) {
343+
// Not only when aliasing but also when parsing the body of an event, we just list the tokens of the
344+
// body in the unknown tokens list, as they define their own statements.
345+
if ($ret->options->has('AS') || $ret->options->has('DO')) {
303346
for (; $list->idx < $list->count; ++$list->idx) {
304347
if ($list->tokens[$list->idx]->type === Token::TYPE_DELIMITER) {
305348
break;

src/Statements/AlterStatement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public function parse(Parser $parser, TokensList $list)
115115
$options = AlterOperation::$VIEW_OPTIONS;
116116
} elseif ($this->options->has('USER')) {
117117
$options = AlterOperation::$USER_OPTIONS;
118+
} elseif ($this->options->has('EVENT')) {
119+
$options = AlterOperation::$EVENT_OPTIONS;
118120
}
119121

120122
$this->altered[] = AlterOperation::parse($parser, $list, $options);

tests/data/parser/parseAlterEvent.out

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -595,38 +595,47 @@
595595
"VIEW_OPTIONS": {
596596
"AS": 1
597597
},
598+
"EVENT_OPTIONS": {
599+
"ON SCHEDULE": 1,
600+
"EVERY": [
601+
2,
602+
"expr"
603+
],
604+
"AT": [
605+
2,
606+
"expr"
607+
],
608+
"STARTS": [
609+
3,
610+
"expr"
611+
],
612+
"ENDS": [
613+
4,
614+
"expr"
615+
],
616+
"ON COMPLETION PRESERVE": 5,
617+
"ON COMPLETION NOT PRESERVE": 5,
618+
"RENAME": 6,
619+
"TO": [
620+
7,
621+
"var"
622+
],
623+
"ENABLE": 8,
624+
"DISABLE": 8,
625+
"DISABLE ON SLAVE": 8,
626+
"COMMENT": [
627+
9,
628+
"var"
629+
],
630+
"DO": 10
631+
},
598632
"options": {
599633
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
600-
"options": []
601-
},
602-
"field": {
603-
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
604-
"ALLOWED_KEYWORDS": {
605-
"AND": 1,
606-
"AS": 1,
607-
"BETWEEN": 1,
608-
"CASE": 1,
609-
"DUAL": 1,
610-
"DIV": 1,
611-
"IS": 1,
612-
"MOD": 1,
613-
"NOT": 1,
614-
"NOT NULL": 1,
615-
"NULL": 1,
616-
"OR": 1,
617-
"OVER": 1,
618-
"REGEXP": 1,
619-
"RLIKE": 1,
620-
"XOR": 1
621-
},
622-
"database": null,
623-
"table": null,
624-
"column": "ENABLE",
625-
"expr": "ENABLE",
626-
"alias": null,
627-
"function": null,
628-
"subquery": null
634+
"options": {
635+
"8": "ENABLE"
636+
}
629637
},
638+
"field": null,
630639
"partitions": null,
631640
"unknown": []
632641
}
@@ -663,14 +672,6 @@
663672
},
664673
"errors": {
665674
"lexer": [],
666-
"parser": [
667-
[
668-
"Unrecognized alter operation.",
669-
{
670-
"@type": "@9"
671-
},
672-
0
673-
]
674-
]
675+
"parser": []
675676
}
676677
}

tests/data/parser/parseAlterEvent2.out

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -595,38 +595,47 @@
595595
"VIEW_OPTIONS": {
596596
"AS": 1
597597
},
598+
"EVENT_OPTIONS": {
599+
"ON SCHEDULE": 1,
600+
"EVERY": [
601+
2,
602+
"expr"
603+
],
604+
"AT": [
605+
2,
606+
"expr"
607+
],
608+
"STARTS": [
609+
3,
610+
"expr"
611+
],
612+
"ENDS": [
613+
4,
614+
"expr"
615+
],
616+
"ON COMPLETION PRESERVE": 5,
617+
"ON COMPLETION NOT PRESERVE": 5,
618+
"RENAME": 6,
619+
"TO": [
620+
7,
621+
"var"
622+
],
623+
"ENABLE": 8,
624+
"DISABLE": 8,
625+
"DISABLE ON SLAVE": 8,
626+
"COMMENT": [
627+
9,
628+
"var"
629+
],
630+
"DO": 10
631+
},
598632
"options": {
599633
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
600-
"options": []
601-
},
602-
"field": {
603-
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
604-
"ALLOWED_KEYWORDS": {
605-
"AND": 1,
606-
"AS": 1,
607-
"BETWEEN": 1,
608-
"CASE": 1,
609-
"DUAL": 1,
610-
"DIV": 1,
611-
"IS": 1,
612-
"MOD": 1,
613-
"NOT": 1,
614-
"NOT NULL": 1,
615-
"NULL": 1,
616-
"OR": 1,
617-
"OVER": 1,
618-
"REGEXP": 1,
619-
"RLIKE": 1,
620-
"XOR": 1
621-
},
622-
"database": null,
623-
"table": null,
624-
"column": "DISABLE",
625-
"expr": "DISABLE",
626-
"alias": null,
627-
"function": null,
628-
"subquery": null
634+
"options": {
635+
"8": "DISABLE"
636+
}
629637
},
638+
"field": null,
630639
"partitions": null,
631640
"unknown": []
632641
}
@@ -663,14 +672,6 @@
663672
},
664673
"errors": {
665674
"lexer": [],
666-
"parser": [
667-
[
668-
"Unrecognized alter operation.",
669-
{
670-
"@type": "@9"
671-
},
672-
0
673-
]
674-
]
675+
"parser": []
675676
}
676677
}

tests/data/parser/parseAlterEvent3.out

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,49 @@
595595
"VIEW_OPTIONS": {
596596
"AS": 1
597597
},
598+
"EVENT_OPTIONS": {
599+
"ON SCHEDULE": 1,
600+
"EVERY": [
601+
2,
602+
"expr"
603+
],
604+
"AT": [
605+
2,
606+
"expr"
607+
],
608+
"STARTS": [
609+
3,
610+
"expr"
611+
],
612+
"ENDS": [
613+
4,
614+
"expr"
615+
],
616+
"ON COMPLETION PRESERVE": 5,
617+
"ON COMPLETION NOT PRESERVE": 5,
618+
"RENAME": 6,
619+
"TO": [
620+
7,
621+
"var"
622+
],
623+
"ENABLE": 8,
624+
"DISABLE": 8,
625+
"DISABLE ON SLAVE": 8,
626+
"COMMENT": [
627+
9,
628+
"var"
629+
],
630+
"DO": 10
631+
},
598632
"options": {
599633
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
600-
"options": []
634+
"options": {
635+
"8": "DISABLE ON SLAVE"
636+
}
601637
},
602638
"field": null,
603639
"partitions": null,
604-
"unknown": [
605-
{
606-
"@type": "@8"
607-
}
608-
]
640+
"unknown": []
609641
}
610642
],
611643
"OPTIONS": {
@@ -640,14 +672,6 @@
640672
},
641673
"errors": {
642674
"lexer": [],
643-
"parser": [
644-
[
645-
"Unrecognized alter operation.",
646-
{
647-
"@type": "@9"
648-
},
649-
0
650-
]
651-
]
675+
"parser": []
652676
}
653677
}

0 commit comments

Comments
 (0)