Skip to content

Commit 09a2385

Browse files
committed
Add a test for CHECK constraint with NOT ENFORCED
1 parent 638bab9 commit 09a2385

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9218,4 +9218,30 @@ public function testAlterTableDropCheckConstraint(): void {
92189218
$result = $this->assertQuery( 'SELECT * FROM t' );
92199219
$this->assertCount( 2, $result );
92209220
}
9221+
9222+
public function testCheckConstraintNotEnforced(): void {
9223+
$this->assertQuery( 'CREATE TABLE t (id INT, CONSTRAINT c CHECK (id > 0) NOT ENFORCED)' );
9224+
9225+
// Insert data that would violate the constraints.
9226+
$this->assertQuery( 'INSERT INTO t (id) VALUES (0)' );
9227+
9228+
$result = $this->assertQuery( 'SELECT * FROM t' );
9229+
$this->assertCount( 1, $result );
9230+
9231+
// SHOW CREATE TABLE
9232+
$this->assertQuery( 'SHOW CREATE TABLE t' );
9233+
$result = $this->engine->get_query_results();
9234+
$this->assertEquals(
9235+
implode(
9236+
"\n",
9237+
array(
9238+
'CREATE TABLE `t` (',
9239+
' `id` int DEFAULT NULL,',
9240+
' CONSTRAINT `c` CHECK ( id > 0 ) /*!80016 NOT ENFORCED */',
9241+
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci',
9242+
)
9243+
),
9244+
$result[0]->{'Create Table'}
9245+
);
9246+
}
92219247
}

0 commit comments

Comments
 (0)