-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maximilian Krög <[email protected]>
- Loading branch information
Showing
10 changed files
with
424 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\SqlParser\Statements; | ||
|
||
use PhpMyAdmin\SqlParser\Components\Expression; | ||
use PhpMyAdmin\SqlParser\Components\OptionsArray; | ||
use PhpMyAdmin\SqlParser\Statement; | ||
|
||
use function trim; | ||
|
||
/** | ||
* `KILL` statement. | ||
* | ||
* KILL [CONNECTION | QUERY] processlist_id | ||
*/ | ||
class KillStatement extends Statement | ||
{ | ||
/** | ||
* Options of this statement. | ||
* | ||
* @var array<string, int|array<int, int|string>> | ||
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})> | ||
*/ | ||
public static $OPTIONS = [ | ||
'CONNECTION' => 1, | ||
'QUERY' => 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\SqlParser\Tests\Parser; | ||
|
||
use PhpMyAdmin\SqlParser\Parser; | ||
use PhpMyAdmin\SqlParser\Statements\KillStatement; | ||
use PhpMyAdmin\SqlParser\Tests\TestCase; | ||
|
||
class KillStatementTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider killProvider | ||
*/ | ||
public function testKill(string $test): void | ||
{ | ||
$this->runParserTest($test); | ||
} | ||
|
||
/** | ||
* @return string[][] | ||
*/ | ||
public function killProvider(): array | ||
{ | ||
return [ | ||
['parser/parseKill'], | ||
['parser/parseKillConnection'], | ||
['parser/parseKillQuery'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider buildKillProvider | ||
*/ | ||
public function testBuildKill(string $sql): void | ||
{ | ||
$parser = new Parser($sql); | ||
$this->assertCount(1, $parser->statements); | ||
$statement = $parser->statements[0]; | ||
$this->assertInstanceOf(KillStatement::class, $statement); | ||
$builtSql = $statement->build(); | ||
$this->assertEquals($sql, $builtSql); | ||
} | ||
|
||
/** | ||
* @return array<int, array<int, string>> | ||
* @psalm-return list<list<string>> | ||
*/ | ||
public function buildKillProvider(): array | ||
{ | ||
return [ | ||
['KILL (SELECT 3 + 4)'], | ||
['KILL QUERY 3'], | ||
['KILL CONNECTION 3'], | ||
['KILL'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
KILL 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"query": "KILL 1", | ||
"lexer": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Lexer", | ||
"str": "KILL 1", | ||
"len": 6, | ||
"last": 6, | ||
"list": { | ||
"@type": "PhpMyAdmin\\SqlParser\\TokensList", | ||
"tokens": [ | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": "KILL", | ||
"value": "KILL", | ||
"keyword": "KILL", | ||
"type": 1, | ||
"flags": 3, | ||
"position": 0 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": " ", | ||
"value": " ", | ||
"keyword": null, | ||
"type": 3, | ||
"flags": 0, | ||
"position": 4 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": "1", | ||
"value": 1, | ||
"keyword": null, | ||
"type": 6, | ||
"flags": 0, | ||
"position": 5 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": null, | ||
"value": null, | ||
"keyword": null, | ||
"type": 9, | ||
"flags": 0, | ||
"position": null | ||
} | ||
], | ||
"count": 4, | ||
"idx": 4 | ||
}, | ||
"delimiter": ";", | ||
"delimiterLen": 1, | ||
"strict": false, | ||
"errors": [] | ||
}, | ||
"parser": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Parser", | ||
"list": { | ||
"@type": "@1" | ||
}, | ||
"statements": [ | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Statements\\KillStatement", | ||
"processListId": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", | ||
"database": null, | ||
"table": null, | ||
"column": null, | ||
"expr": "1", | ||
"alias": null, | ||
"function": null, | ||
"subquery": null | ||
}, | ||
"options": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", | ||
"options": [] | ||
}, | ||
"first": 0, | ||
"last": 2 | ||
} | ||
], | ||
"brackets": 0, | ||
"strict": false, | ||
"errors": [] | ||
}, | ||
"errors": { | ||
"lexer": [], | ||
"parser": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
KILL CONNECTION 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
"query": "KILL CONNECTION 1", | ||
"lexer": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Lexer", | ||
"str": "KILL CONNECTION 1", | ||
"len": 17, | ||
"last": 17, | ||
"list": { | ||
"@type": "PhpMyAdmin\\SqlParser\\TokensList", | ||
"tokens": [ | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": "KILL", | ||
"value": "KILL", | ||
"keyword": "KILL", | ||
"type": 1, | ||
"flags": 3, | ||
"position": 0 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": " ", | ||
"value": " ", | ||
"keyword": null, | ||
"type": 3, | ||
"flags": 0, | ||
"position": 4 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": "CONNECTION", | ||
"value": "CONNECTION", | ||
"keyword": "CONNECTION", | ||
"type": 1, | ||
"flags": 1, | ||
"position": 5 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": " ", | ||
"value": " ", | ||
"keyword": null, | ||
"type": 3, | ||
"flags": 0, | ||
"position": 15 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": "1", | ||
"value": 1, | ||
"keyword": null, | ||
"type": 6, | ||
"flags": 0, | ||
"position": 16 | ||
}, | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Token", | ||
"token": null, | ||
"value": null, | ||
"keyword": null, | ||
"type": 9, | ||
"flags": 0, | ||
"position": null | ||
} | ||
], | ||
"count": 6, | ||
"idx": 6 | ||
}, | ||
"delimiter": ";", | ||
"delimiterLen": 1, | ||
"strict": false, | ||
"errors": [] | ||
}, | ||
"parser": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Parser", | ||
"list": { | ||
"@type": "@1" | ||
}, | ||
"statements": [ | ||
{ | ||
"@type": "PhpMyAdmin\\SqlParser\\Statements\\KillStatement", | ||
"processListId": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", | ||
"database": null, | ||
"table": null, | ||
"column": null, | ||
"expr": "1", | ||
"alias": null, | ||
"function": null, | ||
"subquery": null | ||
}, | ||
"options": { | ||
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", | ||
"options": { | ||
"1": "CONNECTION" | ||
} | ||
}, | ||
"first": 0, | ||
"last": 4 | ||
} | ||
], | ||
"brackets": 0, | ||
"strict": false, | ||
"errors": [] | ||
}, | ||
"errors": { | ||
"lexer": [], | ||
"parser": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
KILL QUERY 1 |
Oops, something went wrong.