Allow parsing KILL statement#557
Conversation
ad4118c to
297929d
Compare
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
|
Could also use diff --git a/src/Statements/KillStatement.php b/src/Statements/KillStatement.php
index 7040a0f3..4ef3f532 100644
--- a/src/Statements/KillStatement.php
+++ b/src/Statements/KillStatement.php
@@ -28,16 +28,22 @@ class KillStatement extends Statement
'QUERY' => 1,
];
+ public static $CLAUSES = [
+ 'KILL' => [
+ 'KILL',
+ 2,
+ ],
+ // Used for options.
+ '_OPTIONS' => [
+ '_OPTIONS',
+ 1,
+ ],
+ 'EXPRESSION' => [
+ 'KILL',
+ 1,
+ ],
+ ];
+
/** @var Expression|null */
public $processListId = null;
-
- public function build(): string
- {
- $option = $this->options === null || $this->options->isEmpty()
- ? ''
- : ' ' . OptionsArray::build($this->options);
- $expression = $this->processListId === null ? '' : ' ' . Expression::build($this->processListId);
-
- return trim('KILL' . $option . $expression);
- }
}
diff --git a/tests/Parser/KillStatementTest.php b/tests/Parser/KillStatementTest.php
index 99b81f75..e3a1e4c8 100644
--- a/tests/Parser/KillStatementTest.php
+++ b/tests/Parser/KillStatementTest.php
@@ -53,7 +53,6 @@ class KillStatementTest extends TestCase
['KILL (SELECT 3 + 4)'],
['KILL QUERY 3'],
['KILL CONNECTION 3'],
- ['KILL'],
];
}
} |
|
LGTM but I don’t know the KILL command 😅 |
| public static $OPTIONS = [ | ||
| 'CONNECTION' => 1, | ||
| 'QUERY' => 1, | ||
| ]; |
There was a problem hiding this comment.
It would be awesome if we could extend support of Maria KILL options
There was a problem hiding this comment.
Oh yeah, makes sense.
| * | ||
| * KILL [CONNECTION | QUERY] processlist_id | ||
| */ | ||
| class KillStatement extends Statement |
There was a problem hiding this comment.
I do believe we need some parsing logic here, so we can accurately validate the statement
| public function buildKillProvider(): array | ||
| { | ||
| return [ | ||
| ['KILL (SELECT 3 + 4)'], |
There was a problem hiding this comment.
is it a valid use case? why would someone need to kill a query or connection that way?
There was a problem hiding this comment.
The use case may be questionable, but the query is valid and working.
There was a problem hiding this comment.
or maybe someone can utilize this by dynamically killing queries that are locking others? by selecting their IDs from the activity? if that's the case, maybe we can also parse the nested select statements? and delegate the building of these queries to their classes? ( most probably it's only SELECT statement that would be allowed ). what do you think?
| ['KILL (SELECT 3 + 4)'], | ||
| ['KILL QUERY 3'], | ||
| ['KILL CONNECTION 3'], | ||
| ['KILL'], |
There was a problem hiding this comment.
This should be invalid, hence why the parsing logic is so important
| ['KILL (SELECT 3 + 4)'], | ||
| ['KILL QUERY 3'], | ||
| ['KILL CONNECTION 3'], | ||
| ['KILL'], |
There was a problem hiding this comment.
I meant KILL is what expected to be invalid
There was a problem hiding this comment.
This is parsed with an error, I was unsure whether it should be able to build a query that was parsed with error. It is probably not needed.
There was a problem hiding this comment.
It's been a while since I interacted with the parser, so I might be mistaken. How this's parsed with an error? if there's no parse function I don't think the statement would be even parsed or validated
| ]; | ||
|
|
||
| /** @var Expression|null */ | ||
| public $processListId = null; |
There was a problem hiding this comment.
I believe we should instead utilize var options instead of using custom option
public static $OPTIONS = [
'CONNECTION' => [
1,
'var',
],
'QUERY' => [
1,
'var',
],
];
Fixes #556