diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index d46a63ec7..7abcff7a8 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -422,7 +422,11 @@ public static function parse(Parser $parser, TokensList $list, array $options = } elseif (($token->value === ',') && ($brackets === 0)) { break; } - } elseif (! self::checkIfTokenQuotedSymbol($token) && $token->type !== Token::TYPE_STRING) { + } elseif ( + ! self::checkIfTokenQuotedSymbol($token) && + $token->type !== Token::TYPE_STRING && + $token->value !== 'CHECK' + ) { if (isset(Parser::$STATEMENT_PARSERS[$arrayKey]) && Parser::$STATEMENT_PARSERS[$arrayKey] !== '') { $list->idx++; // Ignore the current token $nextToken = $list->getNext(); diff --git a/tests/Parser/AlterStatementTest.php b/tests/Parser/AlterStatementTest.php index ac21fe110..41849f7df 100644 --- a/tests/Parser/AlterStatementTest.php +++ b/tests/Parser/AlterStatementTest.php @@ -45,6 +45,7 @@ public function alterProvider(): array ['parser/parseAlterTablePartitionByRange1'], ['parser/parseAlterTablePartitionByRange2'], ['parser/parseAlterTableCoalescePartition'], + ['parser/parseAlterTableAddColumnWithCheck'], ['parser/parseAlterTableAddSpatialIndex1'], ['parser/parseAlterTableDropAddIndex1'], ['parser/parseAlterTableDropColumn1'], diff --git a/tests/data/parser/parseAlterTableAddColumnWithCheck.in b/tests/data/parser/parseAlterTableAddColumnWithCheck.in new file mode 100644 index 000000000..8b5665007 --- /dev/null +++ b/tests/data/parser/parseAlterTableAddColumnWithCheck.in @@ -0,0 +1 @@ +ALTER TABLE `xx` ADD `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`json`)); \ No newline at end of file diff --git a/tests/data/parser/parseAlterTableAddColumnWithCheck.out b/tests/data/parser/parseAlterTableAddColumnWithCheck.out new file mode 100644 index 000000000..06e210c2e --- /dev/null +++ b/tests/data/parser/parseAlterTableAddColumnWithCheck.out @@ -0,0 +1,428 @@ +{ + "query": "ALTER TABLE `xx` ADD `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`json`));", + "lexer": { + "@type": "PhpMyAdmin\\SqlParser\\Lexer", + "str": "ALTER TABLE `xx` ADD `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`json`));", + "len": 115, + "last": 115, + "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": "`xx`", + "value": "xx", + "keyword": null, + "type": 8, + "flags": 2, + "position": 12 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 16 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "ADD", + "value": "ADD", + "keyword": "ADD", + "type": 1, + "flags": 3, + "position": 17 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 20 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`json`", + "value": "json", + "keyword": null, + "type": 8, + "flags": 2, + "position": 21 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 27 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "longtext", + "value": "LONGTEXT", + "keyword": "LONGTEXT", + "type": 1, + "flags": 11, + "position": 28 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 36 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "CHARACTER SET", + "value": "CHARACTER SET", + "keyword": "CHARACTER SET", + "type": 1, + "flags": 7, + "position": 37 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 50 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "utf8mb4", + "value": "utf8mb4", + "keyword": null, + "type": 0, + "flags": 0, + "position": 51 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 58 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "COLLATE", + "value": "COLLATE", + "keyword": "COLLATE", + "type": 1, + "flags": 3, + "position": 59 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 66 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "utf8mb4_bin", + "value": "utf8mb4_bin", + "keyword": null, + "type": 0, + "flags": 0, + "position": 67 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 78 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "NOT NULL", + "value": "NOT NULL", + "keyword": "NOT NULL", + "type": 1, + "flags": 7, + "position": 79 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 87 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "CHECK", + "value": "CHECK", + "keyword": "CHECK", + "type": 1, + "flags": 3, + "position": 88 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": " ", + "value": " ", + "keyword": null, + "type": 3, + "flags": 0, + "position": 93 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 94 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "json_valid", + "value": "json_valid", + "keyword": "JSON_VALID", + "type": 1, + "flags": 33, + "position": 95 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "(", + "value": "(", + "keyword": null, + "type": 2, + "flags": 16, + "position": 105 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": "`json`", + "value": "json", + "keyword": null, + "type": 8, + "flags": 2, + "position": 106 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 112 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ")", + "value": ")", + "keyword": null, + "type": 2, + "flags": 16, + "position": 113 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": ";", + "value": ";", + "keyword": null, + "type": 9, + "flags": 0, + "position": 114 + }, + { + "@type": "PhpMyAdmin\\SqlParser\\Token", + "token": null, + "value": null, + "keyword": null, + "type": 9, + "flags": 0, + "position": null + } + ], + "count": 32, + "idx": 32 + }, + "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": "xx", + "column": null, + "expr": "`xx`", + "alias": null, + "function": null, + "subquery": null + }, + "altered": [ + { + "@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation", + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": { + "1": "ADD" + } + }, + "field": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression", + "database": null, + "table": null, + "column": "json", + "expr": "`json`", + "alias": null, + "function": null, + "subquery": null + }, + "partitions": null, + "unknown": [ + { + "@type": "@12" + }, + { + "@type": "@13" + }, + { + "@type": "@14" + }, + { + "@type": "@15" + }, + { + "@type": "@16" + }, + { + "@type": "@17" + }, + { + "@type": "@18" + }, + { + "@type": "@19" + }, + { + "@type": "@20" + }, + { + "@type": "@21" + }, + { + "@type": "@22" + }, + { + "@type": "@23" + }, + { + "@type": "@24" + }, + { + "@type": "@25" + }, + { + "@type": "@26" + }, + { + "@type": "@27" + }, + { + "@type": "@28" + }, + { + "@type": "@29" + }, + { + "@type": "@30" + }, + { + "@type": "@31" + } + ] + } + ], + "options": { + "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray", + "options": { + "3": "TABLE" + } + }, + "first": 0, + "last": 30 + } + ], + "brackets": 0, + "strict": false, + "errors": [] + }, + "errors": { + "lexer": [], + "parser": [] + } +} \ No newline at end of file