Skip to content

Commit 5448bad

Browse files
Drop support for SQLite Database Integration below 3.0
The plugin loader now requires version 3.0 or higher and fails with a clear error for older releases, then loads the plugin through its wp-includes/database/load.php entry point. The legacy translator, the old AST wrapper and the manual class-by-class fallbacks are removed. The driver factory always constructs WP_MySQL_On_SQLite. Import, Export and Tables drop their legacy result handling, sorting and internal table filtering, since the 3.0 driver handles those. The --enable-ast-driver flag is kept as a deprecated no-op for backward compatibility with existing callers and now emits a warning. Behat scenarios that used the flag run through the normal path, and a new scenario covers the deprecation warning.
1 parent 182bf2c commit 5448bad

13 files changed

Lines changed: 75 additions & 208 deletions

‎AGENTS.md‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ Imports a MySQL dump file into the SQLite database. Parses SQL statements using
1111
**Parameters:**
1212

1313
- `<file>` (required), Path to the SQL dump file. Use `-` to read from STDIN.
14-
- `[--enable-ast-driver]` Enable the AST driver on older integration plugin releases. The current `WP_MySQL_On_SQLite` API is selected automatically when available.
14+
- `[--enable-ast-driver]` Deprecated; accepted as a no-op for backward compatibility.
1515

1616
### `wp sqlite export [<file>]`
1717

18-
Exports the SQLite database to a MySQL-compatible SQL dump file. Generates `DROP TABLE IF EXISTS`, `CREATE TABLE`, and `INSERT INTO` statements for each table. Automatically excludes internal SQLite system tables (`_mysql_data_types_cache`, `sqlite_master`, `sqlite_sequence`, `_wp_sqlite_*`).
18+
Exports the SQLite database to a MySQL-compatible SQL dump file. Generates `DROP TABLE IF EXISTS`, `CREATE TABLE`, and `INSERT INTO` statements for each table. Internal SQLite system tables are never included; the driver's `SHOW TABLES` already excludes them.
1919

2020
**Parameters:**
2121

2222
- `[<file>]` (optional), Output file path. Use `-` to write to STDOUT. Defaults to `{Y-m-d}-{random-hash}.sql`.
2323
- `[--tables=<tables>]` Comma-separated list of tables to include. If omitted, all tables are exported.
2424
- `[--exclude_tables=<tables>]` Comma-separated list of tables to skip.
2525
- `[--porcelain]` Output only the filename (for scripting).
26-
- `[--enable-ast-driver]` Enable the AST driver on older integration plugin releases.
26+
- `[--enable-ast-driver]` Deprecated; accepted as a no-op for backward compatibility.
2727

2828
### `wp sqlite tables`
2929

30-
Lists all user tables in the SQLite database, excluding internal/system tables. With the legacy driver, results are sorted alphabetically.
30+
Lists all user tables in the SQLite database, excluding internal/system tables.
3131

3232
**Parameters:**
3333

3434
- `[--format=<format>]` Output format: `list` (default, one table per line), `csv`, or `json`.
35-
- `[--enable-ast-driver]` Enable the AST driver on older integration plugin releases.
35+
- `[--enable-ast-driver]` Deprecated; accepted as a no-op for backward compatibility.
3636

3737
## Tech Stack
3838

3939
- PHP >=7.4, WP-CLI package (`wp-cli/wp-cli ^2.5`)
4040
- WordPress SQLite Database Integration plugin, translation layer between MySQL queries and SQLite
41-
- The PDO-based `WP_MySQL_On_SQLite` API is selected automatically when available; `WP_SQLite_Translator` and `WP_SQLite_Driver` remain as compatibility fallbacks for older integration plugin releases
41+
- The PDO-based `WP_MySQL_On_SQLite` API (SQLite Database Integration 3.0 or higher) is the only supported driver API
4242

4343
## Directory Structure
4444

@@ -105,17 +105,16 @@ Runs lint, phpcs, phpunit, and behat sequentially.
105105
- `command.php` is the entry point, it registers `wp sqlite` as a WP-CLI command pointing to `SQLite_Command`
106106
- `SQLite_Command` delegates to `Import`, `Export`, and `Tables` classes
107107
- `SQLiteDatabaseIntegrationLoader::load_plugin()` bootstraps the WordPress SQLite Database Integration plugin, which MUST be loaded before any database operations
108-
- `SQLiteDriverFactory::create_driver()` creates the PDO-based `WP_MySQL_On_SQLite` driver when the class is available, with compatibility fallbacks for older integration plugin versions and the legacy translator
108+
- `SQLiteDriverFactory::create_driver()` creates the PDO-based `WP_MySQL_On_SQLite` driver
109109
- The import parser (`Import::parse_statements()`) is a streaming SQL parser using PHP generators, it handles quotes, comments, escape sequences, and multi-line statements character by character
110110

111111
## Common Pitfalls
112112

113113
- **MUST load the SQLite plugin first:** All database operations require `SQLiteDatabaseIntegrationLoader::load_plugin()` to be called before creating a driver. The driver depends on classes from the WordPress SQLite Database Integration plugin.
114-
- **Multiple driver APIs:** Always use `SQLiteDriverFactory::create_driver()`. It selects the PDO-based `WP_MySQL_On_SQLite` API when available and preserves compatibility with older AST drivers and the legacy translator.
114+
- **Driver API:** Always use `SQLiteDriverFactory::create_driver()`. It returns the PDO-based `WP_MySQL_On_SQLite` driver; SQLite Database Integration 3.0 or higher is required.
115115
- **SQL parser edge cases:** The `Import::parse_statements()` method handles escape sequences, nested quotes, and multi-line comments manually. Changes to this parser MUST be tested with the existing Behat scenarios in `features/sqlite-import.feature`.
116116
- **Encoding handling:** Import attempts UTF-8 conversion as a fallback when queries fail. This is intentional error recovery, not a bug.
117117
- **`@when after_wp_config_load`:** All command methods use this WP-CLI hook annotation. New commands MUST include it to ensure WordPress config is loaded before execution.
118-
- **PHPCS inline suppressions:** The codebase uses `@phpcs:disable` / `@phpcs:enable` comments around `define('WP_SQLITE_AST_DRIVER')` because the constant name doesn't follow the project prefix convention. This is intentional.
119118

120119
## Documentation
121120

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $ wp sqlite import <file>
2121
The path to the MySQL compatible dump file to import. When passing `-` as the file argument, the SQL commands are read from standard input.
2222

2323
[--enable-ast-driver]
24-
Enables the AST driver for older integration plugin releases. The current driver API is selected automatically.
24+
Deprecated. Has no effect; the current driver API is always used.
2525

2626
### wp sqlite export
2727

@@ -46,7 +46,7 @@ $ wp sqlite export [<file>] [--tables=<tables>] [--exclude-tables] [--porcelain]
4646
Output filename for the exported database.
4747

4848
[--enable-ast-driver]
49-
Enables the AST driver for older integration plugin releases. The current driver API is selected automatically.
49+
Deprecated. Has no effect; the current driver API is always used.
5050

5151
### wp sqlite tables
5252

@@ -68,7 +68,7 @@ $ wp sqlite tables [--format=<list|csv>]
6868
---
6969

7070
[--enable-ast-driver]
71-
Enables the AST driver for older integration plugin releases. The current driver API is selected automatically.
71+
Deprecated. Has no effect; the current driver API is always used.
7272

7373
**EXAMPLES**
7474

‎features/bootstrap/SQLiteFeatureContext.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public function iExportTheTableWithACommentInjectionName() {
335335
$this->wpcli_tests_invoke_proc(
336336
$this->proc(
337337
sprintf(
338-
'wp sqlite --enable-ast-driver export test_export_comment.sql --tables=%s',
338+
'wp sqlite export test_export_comment.sql --tables=%s',
339339
escapeshellarg( $this->comment_injection_table_name )
340340
)
341341
),

‎features/sqlite-export.feature‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Feature: WP-CLI SQLite Export Command
137137
@require-sqlite
138138
Scenario: Export should quote table names containing backticks
139139
Given the SQLite database contains a table with a backtick in its name
140-
When I run `wp sqlite --enable-ast-driver export test_export_identifier.sql`
140+
When I run `wp sqlite export test_export_identifier.sql`
141141
Then the file "test_export_identifier.sql" should contain:
142142
"""
143143
DROP TABLE IF EXISTS `test``table`;
@@ -151,7 +151,7 @@ Feature: WP-CLI SQLite Export Command
151151
Scenario: Export should keep multiline table names inside comments
152152
Given the SQLite database contains a table with a comment injection name
153153
When I export the table with a comment injection name
154-
And I run `wp sqlite --enable-ast-driver import test_export_comment.sql`
154+
And I run `wp sqlite import test_export_comment.sql`
155155
Then STDOUT should contain:
156156
"""
157157
Success: Imported from 'test_export_comment.sql'.
@@ -175,7 +175,7 @@ Feature: WP-CLI SQLite Export Command
175175
"""
176176
global-color-palette
177177
"""
178-
When I run `wp sqlite --enable-ast-driver import test_export_serialized_settings.sql`
178+
When I run `wp sqlite import test_export_serialized_settings.sql`
179179
Then STDOUT should contain:
180180
"""
181181
Success: Imported from 'test_export_serialized_settings.sql'.
@@ -195,7 +195,7 @@ Feature: WP-CLI SQLite Export Command
195195
"""
196196
'sql-string-escape-bytes','quote\' backslash\\ nul\0 newline\n carriage\r ctrlz\Z end','yes'
197197
"""
198-
When I run `wp sqlite --enable-ast-driver import test_export_escape_bytes.sql`
198+
When I run `wp sqlite import test_export_escape_bytes.sql`
199199
Then STDOUT should contain:
200200
"""
201201
Success: Imported from 'test_export_escape_bytes.sql'.

‎features/sqlite-import.feature‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Feature: WP-CLI SQLite Import Command
5656
INSERT INTO test_table (name) VALUES ('Test that escaping a backslash followed by a character \\a works');
5757
INSERT INTO test_table (name) VALUES ('Test that escaping a backslash and a character \\\a works');
5858
"""
59-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
59+
When I run `wp sqlite import test_import.sql`
6060
Then STDOUT should contain:
6161
"""
6262
Success: Imported from 'test_import.sql'.
@@ -76,7 +76,7 @@ Feature: WP-CLI SQLite Import Command
7676
INSERT INTO test_table (name) VALUES ('Test that a string containing
7777
a newline character and some whitespace works');
7878
"""
79-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
79+
When I run `wp sqlite import test_import.sql`
8080
Then STDOUT should contain:
8181
"""
8282
Success: Imported from 'test_import.sql'.
@@ -103,7 +103,7 @@ Feature: WP-CLI SQLite Import Command
103103
INSERT INTO test_table (name) VALUES ('fo -- this looks like a comment ur');
104104
INSERT INTO test_table (name) VALUES ('fi/* this looks like a comment */ve');
105105
"""
106-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
106+
When I run `wp sqlite import test_import.sql`
107107
Then STDOUT should contain:
108108
"""
109109
Success: Imported from 'test_import.sql'.
@@ -123,7 +123,7 @@ Feature: WP-CLI SQLite Import Command
123123
INSERT INTO test_table (name) VALUES ('a single-quoted string with \' '' some " tricky ` chars');
124124
INSERT INTO test_table (name) VALUES ("a double-quoted string with ' some \" "" tricky ` chars");
125125
"""
126-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
126+
When I run `wp sqlite import test_import.sql`
127127
Then STDOUT should contain:
128128
"""
129129
Success: Imported from 'test_import.sql'.
@@ -144,7 +144,7 @@ Feature: WP-CLI SQLite Import Command
144144
"""
145145
CREATE TABLE `a'strange``identifier\\name` (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
146146
"""
147-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
147+
When I run `wp sqlite import test_import.sql`
148148
Then STDOUT should contain:
149149
"""
150150
Success: Imported from 'test_import.sql'.
@@ -163,7 +163,7 @@ Feature: WP-CLI SQLite Import Command
163163
INSERT INTO test_table (name) VALUES ('Test Name');
164164
165165
"""
166-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
166+
When I run `wp sqlite import test_import.sql`
167167
Then STDOUT should contain:
168168
"""
169169
Success: Imported from 'test_import.sql'.
@@ -183,7 +183,7 @@ Feature: WP-CLI SQLite Import Command
183183
);
184184
INSERT INTO test_table (id) VALUES (1);
185185
"""
186-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
186+
When I run `wp sqlite import test_import.sql`
187187
Then STDOUT should contain:
188188
"""
189189
Success: Imported from 'test_import.sql'.
@@ -205,7 +205,7 @@ Feature: WP-CLI SQLite Import Command
205205
CREATE TABLE wp_zz_parent (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
206206
INSERT INTO wp_zz_parent (id, name) VALUES (1, 'Parent Row');
207207
"""
208-
When I run `wp sqlite --enable-ast-driver import test_import.sql`
208+
When I run `wp sqlite import test_import.sql`
209209
Then STDOUT should contain:
210210
"""
211211
Success: Imported from 'test_import.sql'.

‎features/sqlite-tables.feature‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ Feature: WP-CLI SQLite Tables Command
2525
wp_users
2626
"""
2727

28+
@require-sqlite
29+
Scenario: The deprecated --enable-ast-driver option is accepted as a no-op
30+
When I try `wp sqlite tables --enable-ast-driver`
31+
Then STDERR should contain:
32+
"""
33+
Warning: The --enable-ast-driver option is deprecated and has no effect.
34+
"""
35+
And STDOUT should contain:
36+
"""
37+
wp_users
38+
"""
39+
2840
@require-sqlite
2941
Scenario: Successfully list the tables in the SQLite database in a CSV format
3042
When I run `wp sqlite tables --format=csv`

‎phpstan/stubs.php‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,8 @@ public function quote_identifier( string $identifier ): string {}
2020
public function get_pdo(): PDO {}
2121
}
2222

23-
class WP_SQLite_Driver {
24-
public function __construct( WP_SQLite_Connection $connection, string $db_name ) {}
25-
public function query( string $sql ) {}
26-
public function get_connection(): WP_SQLite_Connection {}
27-
}
28-
2923
// phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO -- Stub for the plugin's PDO subclass.
3024
class WP_MySQL_On_SQLite extends PDO {
3125
public function get_connection(): WP_SQLite_Connection {}
32-
}
33-
34-
class WP_SQLite_Translator {
35-
public function __construct() {}
36-
public function query( string $sql ) {}
37-
public function get_pdo(): PDO {}
26+
public function execute_sqlite_query( string $sql, array $params = array() ): PDOStatement {}
3827
}

‎src/Export.php‎

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
use PDO;
66
use WP_CLI;
77
use WP_MySQL_On_SQLite;
8-
use WP_SQLite_Driver;
9-
use WP_SQLite_Translator;
108

119
class Export {
1210
/**
1311
* The SQLite driver instance.
1412
*
15-
* @var WP_MySQL_On_SQLite|WP_SQLite_Driver|WP_SQLite_Translator
13+
* @var WP_MySQL_On_SQLite
1614
*/
1715
protected $driver;
1816

@@ -93,12 +91,6 @@ protected function write_sql_statements( $handle ) {
9391
continue;
9492
}
9593

96-
// Skip internal tables used by the new SQLite driver
97-
// (This is only needed when exporting with the legacy driver.)
98-
if ( 0 === strpos( $table_name, '_wp_sqlite_' ) ) {
99-
continue;
100-
}
101-
10294
// Skip tables that are in the exclude_tables list
10395
if ( in_array( $table_name, $exclude_tables, true ) ) {
10496
continue;
@@ -118,15 +110,7 @@ protected function write_sql_statements( $handle ) {
118110
*/
119111
protected function get_table_names() {
120112
$result = $this->driver->query( 'SHOW TABLES' );
121-
if ( $this->driver instanceof PDO ) {
122-
return $result->fetchAll( PDO::FETCH_COLUMN );
123-
}
124-
125-
$tables = array();
126-
foreach ( $result as $row ) {
127-
$tables[] = array_values( (array) $row )[0];
128-
}
129-
return $tables;
113+
return $result->fetchAll( PDO::FETCH_COLUMN );
130114
}
131115

132116
/**
@@ -178,14 +162,8 @@ protected function write_insert_statements( $handle, $table_name ) {
178162
*/
179163
protected function get_create_statement( $table_name ) {
180164
$create = $this->driver->query( 'SHOW CREATE TABLE ' . $this->quote_identifier( $table_name ) );
181-
if ( $this->driver instanceof PDO ) {
182-
$sql = $create->fetchColumn( 1 );
183-
return rtrim( $sql, ';' ) . ";\n";
184-
}
185-
186-
$sql = $create[0]->{'Create Table'};
187-
$sql = rtrim( $sql, ';' ); // The old SQLite driver appends a semicolon.
188-
return $sql . ";\n";
165+
$sql = $create->fetchColumn( 1 );
166+
return rtrim( $sql, ';' ) . ";\n";
189167
}
190168

191169
/**
@@ -210,17 +188,7 @@ protected function get_insert_statements( $table_name ) {
210188
* @return array|false|string[]
211189
*/
212190
protected function get_exclude_tables() {
213-
$exclude_tables = isset( $this->args['exclude_tables'] ) ? explode( ',', $this->args['exclude_tables'] ) : [];
214-
return array_merge(
215-
$exclude_tables,
216-
[
217-
// This list is only needed when exporting with the legacy driver.
218-
// In the new SQLite driver, SHOW TABLES never returns these tables.
219-
'_mysql_data_types_cache',
220-
'sqlite_master',
221-
'sqlite_sequence',
222-
]
223-
);
191+
return isset( $this->args['exclude_tables'] ) ? explode( ',', $this->args['exclude_tables'] ) : [];
224192
}
225193

226194
protected function display_result_message( $result_file ) {
@@ -329,12 +297,12 @@ protected function quote_identifier( $identifier ) {
329297
/**
330298
* Get the underlying SQLite PDO instance.
331299
*
300+
* Rows are read through the SQLite PDO directly so that large tables can be
301+
* streamed row by row instead of being materialized by the driver.
302+
*
332303
* @return PDO
333304
*/
334305
protected function get_sqlite_pdo() {
335-
if ( $this->driver instanceof WP_SQLite_Translator ) {
336-
return $this->driver->get_pdo();
337-
}
338306
return $this->driver->get_connection()->get_pdo();
339307
}
340308
}

‎src/Import.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
use Generator;
66
use WP_CLI;
77
use WP_MySQL_On_SQLite;
8-
use WP_SQLite_Driver;
9-
use WP_SQLite_Translator;
108

119
class Import {
1210
/**
1311
* The SQLite driver instance.
1412
*
15-
* @var WP_MySQL_On_SQLite|WP_SQLite_Driver|WP_SQLite_Translator
13+
* @var WP_MySQL_On_SQLite
1614
*/
1715
protected $driver;
1816

0 commit comments

Comments
 (0)