Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Parsers/AlterOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@

// Skipping comments.
if ($token->type === TokenType::Comment) {
continue;

Check warning on line 299 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "Continue_": @@ @@ } // Skipping comments. if ($token->type === TokenType::Comment) { - continue; + break; } // Skipping whitespaces. if ($token->type === TokenType::Whitespace) {
}

// Skipping whitespaces.
if ($token->type === TokenType::Whitespace) {
if ($state === 2) {

Check warning on line 304 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "DecrementInteger": @@ @@ } // Skipping whitespaces. if ($token->type === TokenType::Whitespace) { - if ($state === 2) { + if ($state === 1) { // When parsing the unknown part, the whitespaces are // included to not break anything. $ret->unknown[] = $token;
// When parsing the unknown part, the whitespaces are
// included to not break anything.
$ret->unknown[] = $token;
Expand All @@ -315,7 +315,7 @@
// Not only when aliasing but also when parsing the body of an event, we just list the tokens of the
// body in the unknown tokens list, as they define their own statements.
if ($ret->options->has('AS') || $ret->options->has('DO')) {
for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 318 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ // Not only when aliasing but also when parsing the body of an event, we just list the tokens of the // body in the unknown tokens list, as they define their own statements. if ($ret->options->has('AS') || $ret->options->has('DO')) { - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { if ($list->tokens[$list->idx]->type === TokenType::Delimiter) { break; }
if ($list->tokens[$list->idx]->type === TokenType::Delimiter) {
break;
}
Expand Down Expand Up @@ -355,7 +355,7 @@

$state = 2;
} elseif ($state === 2) {
if (is_string($token->value) || is_int($token->value)) {

Check warning on line 358 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOrSingleSubExprNegation": @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (is_string($token->value) || !is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 358 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOrSingleSubExprNegation": @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (!is_string($token->value) || is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 358 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOrNegation": @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (!(is_string($token->value) || is_int($token->value))) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 358 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOrAllSubExprNegation": @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (!is_string($token->value) || !is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 358 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalOr": @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_int($token->value)) { + if (is_string($token->value) && is_int($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;
$arrayKey = $token->value;
} else {
$arrayKey = $token->token;
Expand All @@ -370,14 +370,14 @@
break;
}
} elseif (! self::checkIfTokenQuotedSymbol($token) && $token->type !== TokenType::String) {
if (isset(Parser::STATEMENT_PARSERS[$arrayKey]) && Parser::STATEMENT_PARSERS[$arrayKey] !== '') {
if (isset(Parser::STATEMENT_PARSERS[$arrayKey]) && Parser::STATEMENT_PARSERS[$arrayKey] !== '' && ! in_array($arrayKey, ['ASC', 'DESC'], true)) {
$list->idx++; // Ignore the current token
$nextToken = $list->getNext();

if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') {
// To avoid adding the tokens between the SET() parentheses to the unknown tokens
$list->getNextOfTypeAndValue(TokenType::Operator, ')');
} elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') {

Check warning on line 380 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAnd": @@ @@ if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') { // To avoid adding the tokens between the SET() parentheses to the unknown tokens $list->getNextOfTypeAndValue(TokenType::Operator, ')'); - } elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') { + } elseif (($token->value === 'SET' || $nextToken !== null) && $nextToken->value === 'DEFAULT') { // to avoid adding the `DEFAULT` token to the unknown tokens. ++$list->idx; } else {
// to avoid adding the `DEFAULT` token to the unknown tokens.
++$list->idx;
} else {
Expand Down Expand Up @@ -409,7 +409,7 @@
if (
($token->type === TokenType::Keyword)
&& (($token->keyword === 'PARTITION BY')
|| ($token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '('))

Check warning on line 412 in src/Parsers/AlterOperations.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAnd": @@ @@ $list->idx++; // Ignore the current token $nextToken = $list->getNext(); - if ($token->type === TokenType::Keyword && ($token->keyword === 'PARTITION BY' || $token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '(')) { + if ($token->type === TokenType::Keyword && ($token->keyword === 'PARTITION BY' || ($token->keyword === 'PARTITION' || $nextToken) && $nextToken->value !== '(')) { $partitionState = 1; } elseif ($token->type === TokenType::Keyword && $token->keyword === 'PARTITION') { $partitionState = 2;
) {
$partitionState = 1;
} elseif (($token->type === TokenType::Keyword) && ($token->keyword === 'PARTITION')) {
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/AlterStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static function alterProvider(): array
['parser/parseAlterTableAddSpatialIndex1'],
['parser/parseAlterTableAddUniqueKey1'],
['parser/parseAlterTableAddUniqueKey2'],
['parser/parseAlterTableAddUniqueKeyDesc'],
['parser/parseAlterTableDropAddIndex1'],
['parser/parseAlterTableDropColumn1'],
['parser/parseAlterTableModifyColumn'],
Expand Down
1 change: 1 addition & 0 deletions tests/data/parser/parseAlterTableAddUniqueKeyDesc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `bad_table_is_bad` ADD UNIQUE KEY `column1` (`column1`,`column2` DESC);
354 changes: 354 additions & 0 deletions tests/data/parser/parseAlterTableAddUniqueKeyDesc.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
{
"query": "ALTER TABLE `bad_table_is_bad` ADD UNIQUE KEY `column1` (`column1`,`column2` DESC);\n",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"strict": false,
"errors": [],
"str": "ALTER TABLE `bad_table_is_bad` ADD UNIQUE KEY `column1` (`column1`,`column2` DESC);\n",
"len": 84,
"last": 84,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"count": 22,
"idx": 22,
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "ALTER",
"value": "ALTER",
"keyword": "ALTER",
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Keyword",
"value": 1
},
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Whitespace",
"value": 3
},
"flags": 0,
"position": 5
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "TABLE",
"value": "TABLE",
"keyword": "TABLE",
"type": {
"@type": "@3"
},
"flags": 3,
"position": 6
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`bad_table_is_bad`",
"value": "bad_table_is_bad",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Symbol",
"value": 8
},
"flags": 2,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 30
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "ADD",
"value": "ADD",
"keyword": "ADD",
"type": {
"@type": "@3"
},
"flags": 3,
"position": 31
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 34
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "UNIQUE KEY",
"value": "UNIQUE KEY",
"keyword": "UNIQUE KEY",
"type": {
"@type": "@3"
},
"flags": 23,
"position": 35
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 45
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`column1`",
"value": "column1",
"keyword": null,
"type": {
"@type": "@9"
},
"flags": 2,
"position": 46
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 55
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "(",
"value": "(",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Operator",
"value": 2
},
"flags": 16,
"position": 56
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`column1`",
"value": "column1",
"keyword": null,
"type": {
"@type": "@9"
},
"flags": 2,
"position": 57
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ",",
"value": ",",
"keyword": null,
"type": {
"@type": "@18"
},
"flags": 16,
"position": 66
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "`column2`",
"value": "column2",
"keyword": null,
"type": {
"@type": "@9"
},
"flags": 2,
"position": 67
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 76
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "DESC",
"value": "DESC",
"keyword": "DESC",
"type": {
"@type": "@3"
},
"flags": 3,
"position": 77
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ")",
"value": ")",
"keyword": null,
"type": {
"@type": "@18"
},
"flags": 16,
"position": 81
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": ";",
"value": ";",
"keyword": null,
"type": {
"@type": "PhpMyAdmin\\SqlParser\\TokenType",
"name": "Delimiter",
"value": 9
},
"flags": 0,
"position": 82
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": {
"@type": "@5"
},
"flags": 0,
"position": 83
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "",
"value": "",
"keyword": null,
"type": {
"@type": "@26"
},
"flags": 0,
"position": null
}
]
},
"delimiter": ";",
"delimiterLen": 1
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"strict": false,
"errors": [],
"list": {
"@type": "@1"
},
"statements": [
{
"@type": "PhpMyAdmin\\SqlParser\\Statements\\AlterStatement",
"table": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": "bad_table_is_bad",
"column": null,
"expr": "`bad_table_is_bad`",
"alias": null,
"function": null,
"subquery": null
},
"altered": [
{
"@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": {
"1": "ADD",
"2": "UNIQUE KEY"
}
},
"field": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
"database": null,
"table": null,
"column": "column1",
"expr": "`column1`",
"alias": null,
"function": null,
"subquery": null
},
"partitions": null,
"unknown": [
{
"@type": "@17"
},
{
"@type": "@19"
},
{
"@type": "@20"
},
{
"@type": "@21"
},
{
"@type": "@22"
},
{
"@type": "@23"
},
{
"@type": "@24"
}
]
}
],
"options": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
"options": {
"3": "TABLE"
}
},
"first": 0,
"last": 19
}
],
"brackets": 0
},
"errors": {
"lexer": [],
"parser": []
}
}
Loading