Skip to content

Commit 9cc84c0

Browse files
committed
Implement DROP CHECK statement
1 parent ea0826c commit 9cc84c0

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

tests/WP_SQLite_Driver_Tests.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9185,8 +9185,13 @@ public function testAlterTableAddCheckConstraint(): void {
91859185
}
91869186

91879187
public function testAlterTableDropCheckConstraint(): void {
9188-
$this->assertQuery( 'CREATE TABLE t (id INT, CONSTRAINT c CHECK (id > 0))' );
9189-
$this->assertQuery( 'ALTER TABLE t DROP CONSTRAINT c' );
9188+
$this->assertQuery( 'CREATE TABLE t (id INT, CONSTRAINT c1 CHECK (id > 0), CONSTRAINT c2 CHECK (id < 10))' );
9189+
9190+
// DROP CONSTRAINT syntax.
9191+
$this->assertQuery( 'ALTER TABLE t DROP CONSTRAINT c1' );
9192+
9193+
// DROP CHECK syntax.
9194+
$this->assertQuery( 'ALTER TABLE t DROP CHECK c2' );
91909195

91919196
// SHOW CREATE TABLE
91929197
$this->assertQuery( 'SHOW CREATE TABLE t' );

wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,13 @@ public function record_alter_table( WP_Parser_Node $node ): void {
682682
continue;
683683
}
684684

685+
// DROP CHECK
686+
if ( $action->has_child_token( WP_MySQL_Lexer::CHECK_SYMBOL ) ) {
687+
$name = $this->get_value( $action->get_first_child_node( 'identifier' ) );
688+
$this->record_drop_check_constraint( $table_is_temporary, $table_name, $name );
689+
continue;
690+
}
691+
685692
// DROP [COLUMN]
686693
$column_ref = $action->get_first_child_node( 'fieldIdentifier' );
687694
if ( null !== $column_ref ) {

0 commit comments

Comments
 (0)