Skip to content

Commit 6706afe

Browse files
committed
Ingore FOREIGN KEY constraint definitions
1 parent f3b4a75 commit 6706afe

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6581,4 +6581,24 @@ public function testRollbackNonExistentTransactionSavepoint(): void {
65816581
$this->expectExceptionMessage( 'no such savepoint: sp1' );
65826582
$this->assertQuery( 'ROLLBACK TO SAVEPOINT sp1' );
65836583
}
6584+
6585+
public function testForeignKeyConstraintAreIgnored(): void {
6586+
/*
6587+
* FOREIGN KEY constraints are not supported yet, they will be ignored.
6588+
* The following query will work, although it references a missing table.
6589+
*/
6590+
$this->assertQuery( 'CREATE TABLE t (id INT, CONSTRAINT c FOREIGN KEY (id) REFERENCES tt (id))' );
6591+
$result = $this->assertQuery( 'SHOW CREATE TABLE t' );
6592+
$this->assertEquals(
6593+
implode(
6594+
"\n",
6595+
array(
6596+
'CREATE TABLE `t` (',
6597+
' `id` int DEFAULT NULL',
6598+
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci',
6599+
)
6600+
),
6601+
$result[0]->{'Create Table'}
6602+
);
6603+
}
65846604
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,12 +1100,13 @@ private function record_add_constraint(
11001100
$keyword = $keyword->get_first_child_token();
11011101
}
11021102

1103-
// FOREIGN KEY and CHECK constraints are not supported yet.
1104-
if (
1105-
WP_MySQL_Lexer::FOREIGN_SYMBOL === $keyword->id
1106-
|| WP_MySQL_Lexer::CHECK_SYMBOL === $keyword->id
1107-
) {
1108-
throw new \Exception( 'FOREIGN KEY and CHECK constraints are not supported yet.' );
1103+
// FOREIGN KEY constraints are not supported yet; they will be ignored.
1104+
// @TODO: Implement support for FOREIGN KEY constraints.
1105+
1106+
// CHECK constraints are not supported yet.
1107+
// @TODO: Implement support for CHECK constraints.
1108+
if ( WP_MySQL_Lexer::CHECK_SYMBOL === $keyword->id ) {
1109+
throw new \Exception( 'CHECK constraints are not supported yet.' );
11091110
}
11101111

11111112
// PRIMARY KEY and UNIQUE require an index.

0 commit comments

Comments
 (0)