Skip to content

Commit 1e4a19a

Browse files
JanJakesashfame
andauthored
Remove legacy SQLite driver (#358)
## Summary Remove the legacy, token-based MySQL-to-SQLite translator and the \`WP_SQLITE_AST_DRIVER\` feature flag. The AST-based driver is now the only driver. ### Changes - Delete 6 legacy driver files (~8,700 lines) and 7 legacy test files (~5,000 lines), along with the root \`phpunit.xml.dist\` and \`composer.json\` test command. - Remove \`WP_SQLITE_AST_DRIVER\` conditionals and \`WP_SQLite_Translator\` branches from \`class-wp-sqlite-db.php\`, \`admin-page.php\`, \`constants.php\`, \`wp-mysql-proxy.php\`, and \`phpcs.xml.dist\`. - Remove legacy driver CI test step and unused \`phpunit-config\` workflow parameter. - Remove DB_NAME fallback in \`db.php\` that was kept for legacy driver compatibility. - Fix dead \`get_error_message()\` call in \`install-functions.php\` left over from the legacy driver API. - Update docs to reflect the removal (\`AGENTS.md\`, \`README.md\`, \`readme.txt\`). ## Test plan - [x] New driver tests pass (635 tests) - [x] PHPCS clean - [x] CI passes --------- Co-authored-by: Ashish Kumar <[email protected]>
1 parent f3ea1a4 commit 1e4a19a

28 files changed

Lines changed: 54 additions & 13984 deletions

.github/workflows/phpunit-tests-run.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ on:
1212
description: 'The version of PHP to use, in the format of X.Y'
1313
required: true
1414
type: 'string'
15-
phpunit-config:
16-
description: 'The PHPUnit configuration file to use'
17-
required: false
18-
type: 'string'
19-
default: 'phpunit.xml.dist'
2015
sqlite:
2116
description: 'SQLite version to install (e.g., 3.24.0). Leave empty for latest version.'
2217
required: false
2318
type: 'string'
2419
default: 'latest'
2520
env:
2621
LOCAL_PHP: ${{ inputs.php }}-fpm
27-
PHPUNIT_CONFIG: ${{ inputs.phpunit-config }}
2822

2923
jobs:
3024
phpunit-tests:
@@ -88,6 +82,3 @@ jobs:
8882
- name: Run PHPUnit tests
8983
run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist
9084
working-directory: packages/mysql-on-sqlite
91-
92-
- name: Run PHPUnit tests for the legacy driver
93-
run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist

.github/workflows/phpunit-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ jobs:
4343
os: ${{ matrix.os }}
4444
php: ${{ matrix.php }}
4545
sqlite: ${{ matrix.sqlite || 'latest' }}
46-
phpunit-config: ${{ 'phpunit.xml.dist' }}

AGENTS.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.5
2828
MySQL syntax from version 5.7 onward, and requires SQLite 3.37.0 or newer
2929
(with legacy mode down to 3.27.0).
3030

31-
### New and old driver
32-
At the moment, the project includes two MySQL-on-SQLite driver implementations:
33-
1. A new, AST-based MySQL-on-SQLite driver (`class-wp-pdo-mysql-on-sqlite.php`).
34-
2. A legacy, token-based MySQL-to-SQLite translator (`class-wp-sqlite-translator.php`).
35-
36-
This state is temporary. The new driver will fully replace the legacy one. New features
37-
must always be implemented in the new driver. The legacy driver can receive small fixes.
38-
The new driver is under a `WP_SQLITE_AST_DRIVER` feature flag, but it is widely used.
39-
4031
## Commands
4132
The codebase is written in PHP and Composer is used to manage the project.
4233
The following commands are useful for development and testing:
@@ -54,10 +45,7 @@ composer run test # Run unit tests
5445
composer run test tests/SomeTest.php # Run specific unit test file
5546
composer run test -- --filter testName # Run specific unit test class/method
5647

57-
# SQLite Database Integration plugin tests
58-
composer run test # Run unit tests
59-
composer run test tests/SomeTest.php # Run specific unit test file
60-
composer run test -- --filter testName # Run specific unit test class/method
48+
# SQLite Database Integration plugin E2E tests
6149
composer run test-e2e # Run E2E tests (Playwright via WP env)
6250

6351
# WordPress tests

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ composer run test # Run unit tests
4343
composer run test tests/SomeTest.php # Run specific unit test file
4444
composer run test -- --filter testName # Run specific unit test class/method
4545

46-
# SQLite Database Integration plugin tests
47-
composer run test # Run unit tests
48-
composer run test tests/SomeTest.php # Run specific unit test file
49-
composer run test -- --filter testName # Run specific unit test class/method
46+
# SQLite Database Integration plugin E2E tests
5047
composer run test-e2e # Run E2E tests (Playwright via WP env)
5148

5249
# WordPress tests

composer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"squizlabs/php_codesniffer": "^3.7",
1919
"wp-coding-standards/wpcs": "^3.1",
2020
"phpcompatibility/phpcompatibility-wp": "*",
21-
"php-parallel-lint/php-parallel-lint": "^1.3",
22-
"yoast/phpunit-polyfills": "2.0.0",
23-
"phpunit/phpunit": "8.5.52"
21+
"php-parallel-lint/php-parallel-lint": "^1.3"
2422
},
2523
"config": {
2624
"allow-plugins": {
@@ -42,9 +40,6 @@
4240
"prepare-release": [
4341
"./bin/prepare-release.sh"
4442
],
45-
"test": [
46-
"phpunit"
47-
],
4843
"test-e2e": [
4944
"@wp-test-ensure-env @no_additional_args",
5045
"rm -f tests/e2e/package.json tests/e2e/node_modules @no_additional_args",

packages/mysql-proxy/bin/wp-mysql-proxy.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
require_once __DIR__ . '/../vendor/autoload.php';
88

9-
define( 'WP_SQLITE_AST_DRIVER', true );
10-
119
// Process CLI arguments:
1210
$shortopts = 'h:d:p:l:';
1311
$longopts = array( 'help', 'database:', 'port:', 'log-level:' );

packages/plugin-sqlite-database-integration/admin-page.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ function sqlite_plugin_adminbar_item( $admin_bar ) {
155155
global $wpdb;
156156

157157
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) {
158-
$suffix = defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ? ' (AST)' : '';
159-
$title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . $suffix . '</span>';
158+
$title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . '</span>';
160159
} elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
161160
$title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'sqlite-database-integration' ) . '</span>';
162161
} else {

packages/plugin-sqlite-database-integration/constants.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,3 @@
5151
define( 'FQDB', FQDBDIR . '.ht.sqlite' );
5252
}
5353
}
54-
55-
// Allow enabling the SQLite AST driver via environment variable.
56-
if ( ! defined( 'WP_SQLITE_AST_DRIVER' ) && isset( $_ENV['WP_SQLITE_AST_DRIVER'] ) && 'true' === $_ENV['WP_SQLITE_AST_DRIVER'] ) {
57-
define( 'WP_SQLITE_AST_DRIVER', true );
58-
}

packages/plugin-sqlite-database-integration/readme.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ SQLite integration plugin by the WordPress Team.
1515

1616
The SQLite plugin is a community, feature plugin. The intent is to allow testing an SQLite integration with WordPress and gather feedback, with the goal of eventually landing it in WordPress core.
1717

18-
This feature plugin includes code from the PHPMyAdmin project (specifically parts of the PHPMyAdmin/sql-parser library), licensed under the GPL v2 or later. More info on the PHPMyAdmin/sql-parser library can be found on [GitHub](https://github.com/phpmyadmin/sql-parser).
19-
2018
== Frequently Asked Questions ==
2119

2220
= What is the purpose of this plugin? =

packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php

Lines changed: 41 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WP_SQLite_DB extends wpdb {
1616
/**
1717
* Database Handle
1818
*
19-
* @var WP_SQLite_Translator
19+
* @var WP_SQLite_Driver
2020
*/
2121
protected $dbh;
2222

@@ -94,10 +94,6 @@ public function get_col_charset( $table, $column ) {
9494
* @param array $modes Optional. A list of SQL modes to set. Default empty array.
9595
*/
9696
public function set_sql_mode( $modes = array() ) {
97-
if ( ! $this->dbh instanceof WP_SQLite_Driver ) {
98-
return;
99-
}
100-
10197
if ( empty( $modes ) ) {
10298
$result = $this->dbh->query( 'SELECT @@SESSION.sql_mode' );
10399
if ( ! isset( $result[0] ) ) {
@@ -175,28 +171,6 @@ public function _real_escape( $data ) {
175171
return $this->add_placeholder_escape( $escaped );
176172
}
177173

178-
/**
179-
* Method to dummy out wpdb::esc_like() function.
180-
*
181-
* WordPress 4.0.0 introduced esc_like() function that adds backslashes to %,
182-
* underscore and backslash, which is not interpreted as escape character
183-
* by SQLite. So we override it and dummy out this function.
184-
*
185-
* @param string $text The raw text to be escaped. The input typed by the user should have no
186-
* extra or deleted slashes.
187-
*
188-
* @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare()
189-
* or real_escape next.
190-
*/
191-
public function esc_like( $text ) {
192-
// The new driver adds "ESCAPE '\\'" to every LIKE expression by default.
193-
// We only need to overload this function to a no-op for the old driver.
194-
if ( $this->dbh instanceof WP_SQLite_Driver ) {
195-
return parent::esc_like( $text );
196-
}
197-
return $text;
198-
}
199-
200174
/**
201175
* Prints SQL/DB error.
202176
*
@@ -326,34 +300,28 @@ public function db_connect( $allow_bail = true ) {
326300
}
327301
}
328302

329-
if ( defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ) {
330-
if ( null === $this->dbname || '' === $this->dbname ) {
331-
$this->bail(
332-
'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables.',
333-
'db_connect_fail'
334-
);
335-
return false;
336-
}
303+
if ( null === $this->dbname || '' === $this->dbname ) {
304+
$this->bail(
305+
'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables.',
306+
'db_connect_fail'
307+
);
308+
return false;
309+
}
337310

338-
$this->ensure_database_directory( FQDB );
339-
340-
try {
341-
$connection = new WP_SQLite_Connection(
342-
array(
343-
'pdo' => $pdo,
344-
'path' => FQDB,
345-
'journal_mode' => defined( 'SQLITE_JOURNAL_MODE' ) ? SQLITE_JOURNAL_MODE : null,
346-
)
347-
);
348-
$this->dbh = new WP_SQLite_Driver( $connection, $this->dbname );
349-
$GLOBALS['@pdo'] = $this->dbh->get_connection()->get_pdo();
350-
} catch ( Throwable $e ) {
351-
$this->last_error = $this->format_error_message( $e );
352-
}
353-
} else {
354-
$this->dbh = new WP_SQLite_Translator( $pdo );
355-
$this->last_error = $this->dbh->get_error_message();
356-
$GLOBALS['@pdo'] = $this->dbh->get_pdo();
311+
$this->ensure_database_directory( FQDB );
312+
313+
try {
314+
$connection = new WP_SQLite_Connection(
315+
array(
316+
'pdo' => $pdo,
317+
'path' => FQDB,
318+
'journal_mode' => defined( 'SQLITE_JOURNAL_MODE' ) ? SQLITE_JOURNAL_MODE : null,
319+
)
320+
);
321+
$this->dbh = new WP_SQLite_Driver( $connection, $this->dbname );
322+
$GLOBALS['@pdo'] = $this->dbh->get_connection()->get_pdo();
323+
} catch ( Throwable $e ) {
324+
$this->last_error = $this->format_error_message( $e );
357325
}
358326
if ( $this->last_error ) {
359327
return false;
@@ -467,11 +435,7 @@ public function query( $query ) {
467435
if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {
468436
$return_val = true;
469437
} elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {
470-
if ( $this->dbh instanceof WP_SQLite_Driver ) {
471-
$this->rows_affected = $this->dbh->get_last_return_value();
472-
} else {
473-
$this->rows_affected = $this->dbh->get_affected_rows();
474-
}
438+
$this->rows_affected = $this->dbh->get_last_return_value();
475439

476440
// Take note of the insert_id.
477441
if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
@@ -516,11 +480,7 @@ public function query( $query ) {
516480
}
517481

518482
// Add SQLite query data.
519-
if ( $this->dbh instanceof WP_SQLite_Driver ) {
520-
$this->queries[ $i ]['sqlite_queries'] = $this->dbh->get_last_sqlite_queries();
521-
} else {
522-
$this->queries[ $i ]['sqlite_queries'] = $this->dbh->executed_sqlite_queries;
523-
}
483+
$this->queries[ $i ]['sqlite_queries'] = $this->dbh->get_last_sqlite_queries();
524484
}
525485
return $return_val;
526486
}
@@ -545,10 +505,6 @@ private function _do_query( $query ) {
545505
$this->last_error = $this->format_error_message( $e );
546506
}
547507

548-
if ( $this->dbh instanceof WP_SQLite_Translator ) {
549-
$this->last_error = $this->dbh->get_error_message();
550-
}
551-
552508
++$this->num_queries;
553509

554510
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
@@ -573,27 +529,23 @@ protected function load_col_info() {
573529
if ( $this->col_info ) {
574530
return;
575531
}
576-
if ( $this->dbh instanceof WP_SQLite_Driver ) {
577-
$this->col_info = array();
578-
foreach ( $this->dbh->get_last_column_meta() as $column ) {
579-
$this->col_info[] = (object) array(
580-
'name' => $column['name'],
581-
'orgname' => $column['mysqli:orgname'],
582-
'table' => $column['table'],
583-
'orgtable' => $column['mysqli:orgtable'],
584-
'def' => '', // Unused, always ''.
585-
'db' => $column['mysqli:db'],
586-
'catalog' => 'def', // Unused, always 'def'.
587-
'max_length' => 0, // As of PHP 8.1, this is always 0.
588-
'length' => $column['len'],
589-
'charsetnr' => $column['mysqli:charsetnr'],
590-
'flags' => $column['mysqli:flags'],
591-
'type' => $column['mysqli:type'],
592-
'decimals' => $column['precision'],
593-
);
594-
}
595-
} else {
596-
$this->col_info = $this->dbh->get_columns();
532+
$this->col_info = array();
533+
foreach ( $this->dbh->get_last_column_meta() as $column ) {
534+
$this->col_info[] = (object) array(
535+
'name' => $column['name'],
536+
'orgname' => $column['mysqli:orgname'],
537+
'table' => $column['table'],
538+
'orgtable' => $column['mysqli:orgtable'],
539+
'def' => '', // Unused, always ''.
540+
'db' => $column['mysqli:db'],
541+
'catalog' => 'def', // Unused, always 'def'.
542+
'max_length' => 0, // As of PHP 8.1, this is always 0.
543+
'length' => $column['len'],
544+
'charsetnr' => $column['mysqli:charsetnr'],
545+
'flags' => $column['mysqli:flags'],
546+
'type' => $column['mysqli:type'],
547+
'decimals' => $column['precision'],
548+
);
597549
}
598550
}
599551

0 commit comments

Comments
 (0)