From 6706afe28fb31ae45c0ba553e55bd519d81c154d Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Fri, 5 Sep 2025 16:25:31 +0200 Subject: [PATCH] Ingore FOREIGN KEY constraint definitions --- tests/WP_SQLite_Driver_Tests.php | 20 +++++++++++++++++++ ...s-wp-sqlite-information-schema-builder.php | 13 ++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/WP_SQLite_Driver_Tests.php b/tests/WP_SQLite_Driver_Tests.php index 915248df..d433cbbd 100644 --- a/tests/WP_SQLite_Driver_Tests.php +++ b/tests/WP_SQLite_Driver_Tests.php @@ -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'} + ); + } } diff --git a/wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php b/wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php index 8baf9071..d837d20f 100644 --- a/wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php +++ b/wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php @@ -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.