From 9c65f9facdb858da55a7ea8d932e4796224205ba Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Wed, 1 Oct 2025 12:10:02 +0200 Subject: [PATCH 1/2] Introduce an unsafe flag for using the new driver with SQLite < 3.37.0 --- .../sqlite-ast/class-wp-sqlite-driver.php | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/wp-includes/sqlite-ast/class-wp-sqlite-driver.php b/wp-includes/sqlite-ast/class-wp-sqlite-driver.php index 2945b7e5..20bef17e 100644 --- a/wp-includes/sqlite-ast/class-wp-sqlite-driver.php +++ b/wp-includes/sqlite-ast/class-wp-sqlite-driver.php @@ -483,13 +483,35 @@ public function __construct( WP_SQLite_Connection $connection, string $database // Check the SQLite version. $sqlite_version = $this->get_sqlite_version(); if ( version_compare( $sqlite_version, self::MINIMUM_SQLITE_VERSION, '<' ) ) { - throw $this->new_driver_exception( - sprintf( - 'The SQLite version %s is not supported. Minimum required version is %s.', - $sqlite_version, - self::MINIMUM_SQLITE_VERSION - ) - ); + if ( defined( 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS' ) && WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS ) { + /* + * SQLite versions prior to 3.37.0 do not support STRICT tables. + * + * However, a database created with SQLite >= 3.37.0 can be used + * with SQLite versions < 3.37.0 when "PRAGMA writable_schema" is + * set to "ON", which also enables error-tolerant schema parsing. + * + * This is an unsafe opt-in feature for special back compatibility + * use cases, as it can corrupt the database by allowing incorrect + * types into STRICT tables. Additionally, depending on the legacy + * SQLite version used, there is no guarantee that all features of + * the SQLite driver will work as expected. Use this with caution. + * + * See: https://www.sqlite.org/stricttables.html#accessing_strict_tables_in_earlier_versions_of_sqlite + * + * TODO: Remove this flag when we drop support for PHP 8.0. + * From PHP 8.1, SQLite 3.46.1 is used by default. + */ + $this->execute_sqlite_query( 'PRAGMA writable_schema=ON' ); + } else { + throw $this->new_driver_exception( + sprintf( + 'The SQLite version %s is not supported. Minimum required version is %s.', + $sqlite_version, + self::MINIMUM_SQLITE_VERSION + ) + ); + } } // Load SQLite version to a property used by WordPress health info. From 5f02fab5152ace05aaa7e6be391e5d70556609af Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Thu, 2 Oct 2025 09:25:47 +0200 Subject: [PATCH 2/2] Add minimum required SQLite version for "WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS" --- wp-includes/sqlite-ast/class-wp-sqlite-driver.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wp-includes/sqlite-ast/class-wp-sqlite-driver.php b/wp-includes/sqlite-ast/class-wp-sqlite-driver.php index 20bef17e..1afce54d 100644 --- a/wp-includes/sqlite-ast/class-wp-sqlite-driver.php +++ b/wp-includes/sqlite-ast/class-wp-sqlite-driver.php @@ -484,6 +484,19 @@ public function __construct( WP_SQLite_Connection $connection, string $database $sqlite_version = $this->get_sqlite_version(); if ( version_compare( $sqlite_version, self::MINIMUM_SQLITE_VERSION, '<' ) ) { if ( defined( 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS' ) && WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS ) { + // When "WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS" is enabled, + // allow using legacy SQLite versions, but not older than 3.27.0. + if ( version_compare( $sqlite_version, '3.27.0', '<' ) ) { + throw $this->new_driver_exception( + sprintf( + 'The SQLite version %s is not supported. Minimum required version is %s.' + . ' With "WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS" enabled, you must use 3.27.0 or newer.', + $sqlite_version, + self::MINIMUM_SQLITE_VERSION + ) + ); + } + /* * SQLite versions prior to 3.37.0 do not support STRICT tables. *