Skip to content

Conversation

JanJakes
Copy link
Member

@JanJakes JanJakes commented Oct 1, 2025

Adds a WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS flag for use with older versions of SQLite.

I came to the conclusion that a special flag with the word UNSAFE might be the best solution here.

By default, the new driver would still throw the following error:

The SQLite version 3.27.2 is not supported. Minimum required version is 3.37.0.

But with the new flag, it could enable accessing a database created with 3.37.0 on older SQLite versions.

An important consideration or TODO:
In this form, it would serve a basic use case, which is opening an existing database on an older SQLite for previews, including writing data to the database.

However, any new CREATE TABLE statement would fail because of the use of the STRICT keyword (General error: 1 near "STRICT": syntax error). We could address that by omitting that keyword in this mode, but maybe let's first determine whether there are use cases for it.

Resolves #252.

Copy link

@sejas sejas left a comment

Choose a reason for hiding this comment

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

Thanks for trying to make work the STRICT tables. I tested this PR on a machine with SQLite 3.34.1 , but I'm getting a weird error when enabling the new AST driver. Database directory is not writable: /srv/htdocs/wp-content/database. There is no more information in debug.log

Screenshot 2025-10-01 at 11 38 25

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).

@JanJakes
Copy link
Member Author

JanJakes commented Oct 2, 2025

@adamziel @akirk Updated with 3.27.0 as a minimum.

Copy link

@sejas sejas left a comment

Choose a reason for hiding this comment

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

Thanks to Jan, I was able to test this PR. I confirm that enabling the correct constants made the WordPress site work on SQLite 3.34.1.

Modified constants:

  • define ( 'WP_SQLITE_AST_DRIVER', true );
  • define ( 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS', true );
  • And setting the correct DB_NAME : `define ( 'DB_NAME', 'database_name_here' );

I wonder if defining the WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS constant is necessary, or if it should be enabled automatically when the SQLite version is older and AST is enabled.

@JanJakes
Copy link
Member Author

JanJakes commented Oct 2, 2025

@sejas

I wonder if defining the WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS constant is necessary, or if it should be enabled automatically when the SQLite version is older and AST is enabled.

With this simple implementation, it's probably necessary (as per the An important consideration or TODO in the description of this issue). But even if we skip the STRICT keyword in all CREATE statements on older versions (= fully implement the mentioned consideration), I would be careful about this hack and would rather caution against it than activate it automatically. It can cause some incompatibilities when writing to the database, and it's technically possible to save incorrect data types, which would make the database file "corrupt" from the perspective of newer SQLite versions.

@JanJakes JanJakes merged commit ea10464 into develop Oct 2, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLite plugin not working on SQLite 3.34.1
4 participants