Skip to content
Merged
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
49 changes: 42 additions & 7 deletions wp-includes/sqlite-ast/class-wp-sqlite-driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,48 @@ 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 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still keep a (lower than above) minimum sqlite version check here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! On PHP 7.2, they seem to package 3.27.2 by default:

docker run --rm php:7.2 -r "print_r((new PDO('sqlite::memory'))->query('SELECT SQLITE_VERSION();')->fetch());"

And given that 3.27.1 and 3.27.2 were bugfix releases, I think we can go with 3.27.0 (February 2019).

// 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.
*
* 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.
Expand Down
Loading