Skip to content

Commit f136374

Browse files
Merge pull request #554 from MoonE/support-alter-table-with-column-check-constraint
Allow parsing ALTER TABLE statement with column check constraint
2 parents 29f982a + 692cecf commit f136374

File tree

4 files changed

+435
-1
lines changed

4 files changed

+435
-1
lines changed

src/Components/AlterOperation.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
422422
} elseif (($token->value === ',') && ($brackets === 0)) {
423423
break;
424424
}
425-
} elseif (! self::checkIfTokenQuotedSymbol($token) && $token->type !== Token::TYPE_STRING) {
425+
} elseif (
426+
! self::checkIfTokenQuotedSymbol($token) &&
427+
$token->type !== Token::TYPE_STRING &&
428+
$token->value !== 'CHECK'
429+
) {
426430
if (isset(Parser::$STATEMENT_PARSERS[$arrayKey]) && Parser::$STATEMENT_PARSERS[$arrayKey] !== '') {
427431
$list->idx++; // Ignore the current token
428432
$nextToken = $list->getNext();

tests/Parser/AlterStatementTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function alterProvider(): array
4545
['parser/parseAlterTablePartitionByRange1'],
4646
['parser/parseAlterTablePartitionByRange2'],
4747
['parser/parseAlterTableCoalescePartition'],
48+
['parser/parseAlterTableAddColumnWithCheck'],
4849
['parser/parseAlterTableAddSpatialIndex1'],
4950
['parser/parseAlterTableDropAddIndex1'],
5051
['parser/parseAlterTableDropColumn1'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `xx` ADD `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`json`));

0 commit comments

Comments
 (0)