Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -6581,4 +6581,24 @@ public function testRollbackNonExistentTransactionSavepoint(): void {
$this->expectExceptionMessage( 'no such savepoint: sp1' );
$this->assertQuery( 'ROLLBACK TO SAVEPOINT sp1' );
}

public function testForeignKeyConstraintAreIgnored(): void {
/*
* FOREIGN KEY constraints are not supported yet, they will be ignored.
* The following query will work, although it references a missing table.
*/
$this->assertQuery( 'CREATE TABLE t (id INT, CONSTRAINT c FOREIGN KEY (id) REFERENCES tt (id))' );
$result = $this->assertQuery( 'SHOW CREATE TABLE t' );
$this->assertEquals(
implode(
"\n",
array(
'CREATE TABLE `t` (',
' `id` int DEFAULT NULL',
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci',
)
),
$result[0]->{'Create Table'}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,13 @@ private function record_add_constraint(
$keyword = $keyword->get_first_child_token();
}

// FOREIGN KEY and CHECK constraints are not supported yet.
if (
WP_MySQL_Lexer::FOREIGN_SYMBOL === $keyword->id
|| WP_MySQL_Lexer::CHECK_SYMBOL === $keyword->id
) {
throw new \Exception( 'FOREIGN KEY and CHECK constraints are not supported yet.' );
// FOREIGN KEY constraints are not supported yet; they will be ignored.
// @TODO: Implement support for FOREIGN KEY constraints.

// CHECK constraints are not supported yet.
// @TODO: Implement support for CHECK constraints.
if ( WP_MySQL_Lexer::CHECK_SYMBOL === $keyword->id ) {
throw new \Exception( 'CHECK constraints are not supported yet.' );
}

// PRIMARY KEY and UNIQUE require an index.
Expand Down
Loading