Skip to content

Commit 1bc31c3

Browse files
committed
Remove WP_SQLITE_AST_DRIVER feature flag and legacy driver references
The AST-based driver is now the only driver. Remove all conditional logic that branched between the new and legacy driver: - db.php: Always load the new driver. - class-wp-sqlite-db.php: Remove WP_SQLite_Translator instanceof checks, simplify all methods to use WP_SQLite_Driver directly. - install-functions.php: Always use WP_SQLite_Driver. - admin-page.php: Remove "(AST)" suffix from admin bar. - constants.php: Remove WP_SQLITE_AST_DRIVER env var handling. - wp-setup.sh: Remove WP_SQLITE_AST_DRIVER env vars from Docker. - wp-mysql-proxy.php: Remove WP_SQLITE_AST_DRIVER define. - phpcs.xml.dist: Remove legacy translator exclusion.
1 parent 522724d commit 1bc31c3

8 files changed

Lines changed: 49 additions & 128 deletions

File tree

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/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

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,7 @@
4747
);
4848
}
4949

50-
if ( defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ) {
51-
require_once __DIR__ . '/../database/load.php';
52-
} else {
53-
require_once __DIR__ . '/php-polyfills.php';
54-
require_once __DIR__ . '/class-wp-sqlite-lexer.php';
55-
require_once __DIR__ . '/class-wp-sqlite-query-rewriter.php';
56-
require_once __DIR__ . '/class-wp-sqlite-translator.php';
57-
require_once __DIR__ . '/class-wp-sqlite-token.php';
58-
require_once __DIR__ . '/class-wp-sqlite-pdo-user-defined-functions.php';
59-
}
50+
require_once __DIR__ . '/../database/load.php';
6051
require_once __DIR__ . '/class-wp-sqlite-db.php';
6152
require_once __DIR__ . '/install-functions.php';
6253

packages/plugin-sqlite-database-integration/wp-includes/sqlite/install-functions.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@ function sqlite_make_db_sqlite() {
3434
wp_die( $message, 'Database Error!' );
3535
}
3636

37-
if ( defined( 'WP_SQLITE_AST_DRIVER' ) && WP_SQLITE_AST_DRIVER ) {
38-
$translator = new WP_SQLite_Driver(
39-
new WP_SQLite_Connection( array( 'pdo' => $pdo ) ),
40-
$wpdb->dbname
41-
);
42-
} else {
43-
$translator = new WP_SQLite_Translator( $pdo );
44-
}
45-
$query = null;
37+
$translator = new WP_SQLite_Driver(
38+
new WP_SQLite_Connection( array( 'pdo' => $pdo ) ),
39+
$wpdb->dbname
40+
);
41+
$query = null;
4642

4743
try {
4844
$translator->begin_transaction();
@@ -52,10 +48,7 @@ function sqlite_make_db_sqlite() {
5248
continue;
5349
}
5450

55-
$result = $translator->query( $query );
56-
if ( false === $result ) {
57-
throw new PDOException( $translator->get_error_message() );
58-
}
51+
$translator->query( $query );
5952
}
6053
$translator->commit();
6154
} catch ( PDOException $err ) {

phpcs.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
-->
6363

6464
<rule ref="WordPress.DB.RestrictedClasses.mysql__PDO">
65-
<exclude-pattern>/packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php</exclude-pattern>
6665
<exclude-pattern>/packages/mysql-on-sqlite/src/sqlite/*\.php</exclude-pattern>
6766
<exclude-pattern>/tests/*</exclude-pattern>
6867
</rule>

wp-setup.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,20 @@ echo "Adding 'docker-compose.override.yml' to the WordPress repository..."
3131
cat << EOF > "$WP_DIR/docker-compose.override.yml"
3232
services:
3333
wordpress-develop:
34-
environment:
35-
WP_SQLITE_AST_DRIVER: true
3634
volumes:
3735
- ../packages/plugin-sqlite-database-integration:/var/www/src/wp-content/plugins/sqlite-database-integration
3836
- ../packages/mysql-on-sqlite/src:/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database
3937
4038
php:
4139
# PHP temporarily pinned to 8.3.10, see: https://github.com/WordPress/wordpress-develop/pull/9602
4240
image: wordpressdevelop/php@sha256:c0ba85936a9d1ac2c98bf3da2d62ceb0e5787a6b11e383630df0c5a5bf2534b5
43-
environment:
44-
WP_SQLITE_AST_DRIVER: true
4541
volumes:
4642
- ../packages/plugin-sqlite-database-integration:/var/www/src/wp-content/plugins/sqlite-database-integration
4743
- ../packages/mysql-on-sqlite/src:/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database
4844
4945
cli:
5046
# PHP temporarily pinned to 8.3.10, see: https://github.com/WordPress/wordpress-develop/pull/9602
5147
image: wordpressdevelop/cli@sha256:85ad7d7a9c3bd9a8775fc83aea7f7dfc0aad25b2bc4f7d740696b28cd2a0ef89
52-
environment:
53-
WP_SQLITE_AST_DRIVER: true
5448
volumes:
5549
- ../packages/plugin-sqlite-database-integration:/var/www/src/wp-content/plugins/sqlite-database-integration
5650
- ../packages/mysql-on-sqlite/src:/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database

0 commit comments

Comments
 (0)