From eb9ef6a83e7444501c920e177f7e547a3f08dc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Thu, 1 Oct 2026 20:48:42 +0200 Subject: [PATCH 1/5] Prefer DB_PATH for SQLite database commands Use the database selected by WordPress when legacy constants conflict, while retaining the existing fallback for older plugin versions. Cover file operations with conflicting, matching, and legacy settings, including checks that the other database remains unchanged. https://github.com/WordPress/sqlite-database-integration/pull/512 --- features/db-sqlite-path.feature | 62 +++++++++++++++++++++++++++++++++ src/DB_Command_SQLite.php | 4 +++ 2 files changed, 66 insertions(+) create mode 100644 features/db-sqlite-path.feature diff --git a/features/db-sqlite-path.feature b/features/db-sqlite-path.feature new file mode 100644 index 00000000..60da84b5 --- /dev/null +++ b/features/db-sqlite-path.feature @@ -0,0 +1,62 @@ +@require-sqlite +Feature: Select the configured SQLite database for file operations + + Scenario Outline: Use the effective database path without changing another database + Given a WP install + When I run `wp eval 'copy( defined( "DB_PATH" ) ? DB_PATH : FQDB, "selected.sqlite" ); copy( "selected.sqlite", "other.sqlite" );'` + And I run `sqlite3 selected.sqlite "CREATE TABLE path_marker (value TEXT); INSERT INTO path_marker VALUES ('selected');"` + And I run `sqlite3 other.sqlite "CREATE TABLE path_marker (value TEXT); INSERT INTO path_marker VALUES ('other');"` + + Given a paths.php file: + """ + ' ) { + define( 'DB_PATH', __DIR__ . '/' ); + } + if ( '' !== '' ) { + define( 'FQDB', __DIR__ . '/' ); + } + if ( '' !== '' ) { + define( 'DB_DIR', __DIR__ . '/' ); + } + if ( '' !== '' ) { + define( 'DB_FILE', '' ); + } + if ( '' !== '' ) { + define( 'FQDBDIR', __DIR__ . '/' ); + } + """ + When I run `wp config set path_constants "require __DIR__ . '/paths.php'" --type=variable --raw` + And I try `wp eval 'echo "ready";'` + Then the return code should be 0 + + When I run `php -r 'echo md5_file( "other.sqlite" );'` + Then save STDOUT as {OTHER_HASH} + + When I try `wp db export selected.sql` + Then the return code should be 0 + And the selected.sql file should contain: + """ + INSERT INTO path_marker VALUES('selected'); + """ + And the selected.sql file should not contain: + """ + INSERT INTO path_marker VALUES('other'); + """ + + When I try `wp db drop --yes` + Then the return code should be 0 + And the selected.sqlite file should not exist + + When I run `php -r 'echo md5_file( "other.sqlite" );'` + Then STDOUT should be: + """ + {OTHER_HASH} + """ + + Examples: + | db_path | fqdb | db_dir | db_file | fqdbdir | + | selected.sqlite | other.sqlite | other | other.sqlite | other/ | + | selected.sqlite | selected.sqlite | / | selected.sqlite | / | + | | selected.sqlite | | | | + | | | | selected.sqlite | / | diff --git a/src/DB_Command_SQLite.php b/src/DB_Command_SQLite.php index 4ffe93a3..4ea185a7 100644 --- a/src/DB_Command_SQLite.php +++ b/src/DB_Command_SQLite.php @@ -63,6 +63,10 @@ protected function is_sqlite() { * @return string|false Path to SQLite database file, or false if not found. */ protected function get_sqlite_db_path() { + if ( defined( 'DB_PATH' ) ) { + return DB_PATH; + } + // Check for FQDB constant (fully qualified database path). if ( defined( 'FQDB' ) ) { return FQDB; From 2b5016be2e8765641a6b0a4108a0d0054cff078f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Mon, 5 Oct 2026 11:17:40 +0200 Subject: [PATCH 2/5] Use portable quoting for SQLite path tests Double-quote the PHP command-line argument so the database hash checks also run under Windows cmd.exe. --- features/db-sqlite-path.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/db-sqlite-path.feature b/features/db-sqlite-path.feature index 60da84b5..216ad6b5 100644 --- a/features/db-sqlite-path.feature +++ b/features/db-sqlite-path.feature @@ -30,7 +30,7 @@ Feature: Select the configured SQLite database for file operations And I try `wp eval 'echo "ready";'` Then the return code should be 0 - When I run `php -r 'echo md5_file( "other.sqlite" );'` + When I run `php -r "echo md5_file( 'other.sqlite' );"` Then save STDOUT as {OTHER_HASH} When I try `wp db export selected.sql` @@ -48,7 +48,7 @@ Feature: Select the configured SQLite database for file operations Then the return code should be 0 And the selected.sqlite file should not exist - When I run `php -r 'echo md5_file( "other.sqlite" );'` + When I run `php -r "echo md5_file( 'other.sqlite' );"` Then STDOUT should be: """ {OTHER_HASH} From 592febbb95e2205298d8ea92e25ba1d04cd931e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Mon, 5 Oct 2026 12:53:18 +0200 Subject: [PATCH 3/5] Enable SQLite deletion tests on Windows Remove the Windows skips from the SQLite CRUD and export/import scenarios. Both pass repeatedly with SQLite integration 3.0.2 and the merged DB_PATH changes on Windows Server 2022 with PHP 8.5. The skips predate the plugin's connection cleanup in close(), which appears to resolve the file-locking failures. https://github.com/wp-cli/db-command/pull/323 https://github.com/WordPress/sqlite-database-integration/pull/331 https://github.com/JanJakes/db-command/actions/runs/37290138622 --- features/db.feature | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/features/db.feature b/features/db.feature index 2fcbe899..07656dcb 100644 --- a/features/db.feature +++ b/features/db.feature @@ -387,8 +387,7 @@ Feature: Perform database operations Query succeeded. Rows affected: 1 """ - @require-sqlite @skip-windows - # Skipped on Windows due to persistent file locking issues when run via Behat. + @require-sqlite Scenario: SQLite DB CRUD operations Given a WP install And a session_yes file: @@ -425,8 +424,7 @@ Feature: Perform database operations total """ - @require-sqlite @skip-windows - # Skipped on Windows due to persistent file locking issues when run via Behat. + @require-sqlite Scenario: SQLite DB export/import Given a WP install And a session_yes file: From 7e327c8c637b342d9ed21d48c1e13c003faf2d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Mon, 5 Oct 2026 13:05:59 +0200 Subject: [PATCH 4/5] Reject file operations on in-memory SQLite databases Reject :memory: after resolving DB_PATH or legacy FQDB so file operations fail with a clear error. Keep queries available through the active SQLite connection. https://github.com/wp-cli/db-command/pull/351#discussion_r4172913203 --- features/db-sqlite-path.feature | 34 +++++++++++++++++++++++++++++++++ src/DB_Command_SQLite.php | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/features/db-sqlite-path.feature b/features/db-sqlite-path.feature index 216ad6b5..90f5ace4 100644 --- a/features/db-sqlite-path.feature +++ b/features/db-sqlite-path.feature @@ -60,3 +60,37 @@ Feature: Select the configured SQLite database for file operations | selected.sqlite | selected.sqlite | / | selected.sqlite | / | | | selected.sqlite | | | | | | | | selected.sqlite | / | + + Scenario Outline: Reject file operations on an in-memory SQLite database + Given a WP install + And an input.sql file: + """ + SELECT 1; + """ + When I run `wp config set :memory:` + And I run `wp db query "SELECT 1 AS value" --skip-column-names` + Then STDOUT should be: + """ + 1 + """ + + When I try `wp db ` + Then the return code should be 1 + And STDERR should be: + """ + Error: This command does not support in-memory SQLite databases. + """ + And STDOUT should be empty + + Examples: + | constant | command | + | DB_PATH | create | + | DB_PATH | drop --yes | + | DB_PATH | reset --yes | + | DB_PATH | export output.sql | + | DB_PATH | import input.sql | + | FQDB | create | + | FQDB | drop --yes | + | FQDB | reset --yes | + | FQDB | export output.sql | + | FQDB | import input.sql | diff --git a/src/DB_Command_SQLite.php b/src/DB_Command_SQLite.php index 4ea185a7..b864bf19 100644 --- a/src/DB_Command_SQLite.php +++ b/src/DB_Command_SQLite.php @@ -64,11 +64,19 @@ protected function is_sqlite() { */ protected function get_sqlite_db_path() { if ( defined( 'DB_PATH' ) ) { + if ( ':memory:' === DB_PATH ) { + WP_CLI::error( 'This command does not support in-memory SQLite databases.' ); + } + return DB_PATH; } // Check for FQDB constant (fully qualified database path). if ( defined( 'FQDB' ) ) { + if ( ':memory:' === FQDB ) { + WP_CLI::error( 'This command does not support in-memory SQLite databases.' ); + } + return FQDB; } From e2c2f8a416c536df2de4df7596cf4dcd28132f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Mon, 5 Oct 2026 13:28:41 +0200 Subject: [PATCH 5/5] Use WP-CLI for SQLite test hash checks Skip WordPress loading so hashing after database deletion does not recreate the database. --- features/db-sqlite-path.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/db-sqlite-path.feature b/features/db-sqlite-path.feature index 90f5ace4..37e7de1d 100644 --- a/features/db-sqlite-path.feature +++ b/features/db-sqlite-path.feature @@ -30,7 +30,7 @@ Feature: Select the configured SQLite database for file operations And I try `wp eval 'echo "ready";'` Then the return code should be 0 - When I run `php -r "echo md5_file( 'other.sqlite' );"` + When I run `wp eval 'echo md5_file( "other.sqlite" );' --skip-wordpress` Then save STDOUT as {OTHER_HASH} When I try `wp db export selected.sql` @@ -48,7 +48,7 @@ Feature: Select the configured SQLite database for file operations Then the return code should be 0 And the selected.sqlite file should not exist - When I run `php -r "echo md5_file( 'other.sqlite' );"` + When I run `wp eval 'echo md5_file( "other.sqlite" );' --skip-wordpress` Then STDOUT should be: """ {OTHER_HASH}