From 2d2e057e967ef7a246846c9470c975c1561257a9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Aug 2026 08:23:18 +0000 Subject: [PATCH 1/2] Adapt SQLite tests to sqlite-database-integration 3.0 The 3.0 release of the SQLite drop-in replaced the old translation layer with the MySQL-on-SQLite driver, which changes three things the Behat suite relied on. All `SQLite` matrix jobs went red as a result, while the MySQL/MariaDB jobs stayed green. `SHOW TABLES` now sorts by table name and honors a `WHERE` clause, so `wp db tables` returns the same alphabetically sorted list it returns on MySQL. The `@require-sqlite` variants of the two `db tables` scenarios only differed from their MySQL counterparts in that ordering, so drop the duplicates and let the original scenarios cover both database types. `SHOW COLUMNS` now reports MySQL types instead of the underlying SQLite storage types, and no longer quotes an absent default, so `db columns` reports `date`/`text` with an empty default rather than `TEXT`/`''`. Finally, the driver rejects multi-queries, and a query with redundant trailing semicolons parses as one. The MySQL client silently ignores the empty statements they produce, so trim them in the SQLite query path to keep `wp db query` behaving the same on both. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01MXbmdB7hvQ2jwEe64h6s5K --- features/db-columns.feature | 5 +- features/db-tables.feature | 114 +----------------------------------- src/DB_Command_SQLite.php | 13 ++++ 3 files changed, 17 insertions(+), 115 deletions(-) diff --git a/features/db-columns.feature b/features/db-columns.feature index ba55cf6b..a7f08ab6 100644 --- a/features/db-columns.feature +++ b/features/db-columns.feature @@ -58,7 +58,8 @@ Feature: Display information about a given table. And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"` When I try `wp db columns not_wp` + # The `Extra` column is left out because `wp db columns` omits it on SQLite. Then STDOUT should be a table containing rows: | Field | Type | Null | Key | Default | - | date | TEXT | NO | PRI | '' | - | awesome_stuff | TEXT | YES | | | + | date | date | NO | PRI | | + | awesome_stuff | text | YES | | | diff --git a/features/db-tables.feature b/features/db-tables.feature index cb3f6810..98209eb2 100644 --- a/features/db-tables.feature +++ b/features/db-tables.feature @@ -1,6 +1,5 @@ Feature: List database tables - @require-mysql-or-mariadb Scenario: List database tables on a single WordPress install Given a WP install @@ -36,40 +35,7 @@ Feature: List database tables wp_postmeta,wp_posts """ - @require-sqlite - Scenario: List database tables on a single WordPress install - Given a WP install - - When I run `wp db tables` - Then STDOUT should contain: - """ - wp_users - wp_usermeta - wp_termmeta - wp_terms - wp_term_taxonomy - wp_term_relationships - wp_commentmeta - wp_comments - wp_links - wp_options - wp_postmeta - wp_posts - """ - - When I run `wp db tables --format=csv` - Then STDOUT should contain: - """ - ,wp_commentmeta,wp_comments, - """ - - When I run `wp db tables 'wp_post*' --format=csv` - Then STDOUT should be: - """ - wp_postmeta,wp_posts - """ - - @require-wp-3.9 @require-mysql-or-mariadb + @require-wp-3.9 Scenario: List database tables on a multisite WordPress install Given a WP multisite install @@ -153,84 +119,6 @@ Feature: List database tables wp_posts """ - @require-sqlite - Scenario: List database tables on a multisite WordPress install - Given a WP multisite install - - When I run `wp db tables` - Then STDOUT should contain: - """ - wp_users - wp_usermeta - wp_termmeta - wp_terms - wp_term_taxonomy - wp_term_relationships - wp_commentmeta - wp_comments - wp_links - wp_options - wp_postmeta - wp_posts - wp_blogs - wp_blogmeta - wp_registration_log - wp_site - wp_sitemeta - wp_signups - """ - - When I run `wp site create --slug=foo` - And I run `wp db tables --url=example.com/foo` - Then STDOUT should contain: - """ - wp_users - """ - And STDOUT should contain: - """ - wp_usermeta - """ - And STDOUT should contain: - """ - wp_2_posts - """ - - When I run `wp db tables --url=example.com/foo --scope=global` - Then STDOUT should not contain: - """ - wp_2_posts - """ - - When I run `wp db tables --all-tables-with-prefix` - Then STDOUT should contain: - """ - wp_2_posts - """ - And STDOUT should contain: - """ - wp_posts - """ - - When I run `wp db tables --url=example.com/foo --all-tables-with-prefix` - Then STDOUT should contain: - """ - wp_2_posts - """ - And STDOUT should not contain: - """ - wp_posts - """ - - When I run `wp db tables --url=example.com/foo --network` - Then STDOUT should contain: - """ - wp_2_posts - """ - And STDOUT should contain: - """ - wp_posts - """ - # AUTO_INCREMENT doesn't work with SQLite. @require-mysql-or-mariadb Scenario: Listing a site's tables should only list that site's tables diff --git a/src/DB_Command_SQLite.php b/src/DB_Command_SQLite.php index 6a7c107f..120819b5 100644 --- a/src/DB_Command_SQLite.php +++ b/src/DB_Command_SQLite.php @@ -221,6 +221,19 @@ protected function sqlite_query( $query, $assoc_args = [] ) { WP_CLI::error( 'SQLite database not available.' ); } + /* + * Strip redundant trailing semicolons and whitespace. + * + * The MySQL client silently ignores the empty statements they produce, + * whereas the SQLite drop-in parses them as a multi-query and bails out + * with "Multi-query is not supported.". Trim them for parity. + */ + $query = rtrim( $query, "; \t\n\r\0\x0B" ); + + if ( '' === $query ) { + WP_CLI::error( 'No query specified.' ); + } + $skip_column_names = Utils\get_flag_value( $assoc_args, 'skip-column-names', false ); try { From e2c502e626083d18b7c0e6cf2bd8dd0b3aa0b92d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Aug 2026 08:52:23 +0000 Subject: [PATCH 2/2] Show the `Extra` column in `wp db columns` on SQLite `columns()` dropped `Extra` from the output on SQLite because the old SQLite drop-in did not return that field from `SHOW COLUMNS`. The MySQL-on-SQLite driver in sqlite-database-integration 3.0 returns the full MySQL-compatible column set, so the workaround now hides information that is available, notably `auto_increment`. With `Extra` restored, the SQLite variant of the `db columns` scenario expects exactly what the MySQL variant does, so drop the duplicate. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01MXbmdB7hvQ2jwEe64h6s5K --- features/db-columns.feature | 13 ------------- src/DB_Command.php | 4 ---- 2 files changed, 17 deletions(-) diff --git a/features/db-columns.feature b/features/db-columns.feature index a7f08ab6..d6aa305b 100644 --- a/features/db-columns.feature +++ b/features/db-columns.feature @@ -41,7 +41,6 @@ Feature: Display information about a given table. Couldn't find any tables matching: wp_foobar """ - @require-mysql-or-mariadb Scenario: Display information about a non default WordPress table Given a WP install And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"` @@ -51,15 +50,3 @@ Feature: Display information about a given table. | Field | Type | Null | Key | Default | Extra | | date | date | NO | PRI | | | | awesome_stuff | text | YES | | | | - - @require-sqlite - Scenario: Display information about a non default WordPress table - Given a WP install - And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"` - - When I try `wp db columns not_wp` - # The `Extra` column is left out because `wp db columns` omits it on SQLite. - Then STDOUT should be a table containing rows: - | Field | Type | Null | Key | Default | - | date | date | NO | PRI | | - | awesome_stuff | text | YES | | | diff --git a/src/DB_Command.php b/src/DB_Command.php index be9f14fc..a82392dd 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -1942,10 +1942,6 @@ public function columns( $args, $assoc_args ) { $formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra' ]; - if ( $this->is_sqlite() ) { - $formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default' ]; - } - $formatter_args = [ 'format' => $format, ];