Skip to content

Commit 21826d5

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 1aeb94d commit 21826d5

8 files changed

Lines changed: 48 additions & 107 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: 42 additions & 73 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] ) ) {
@@ -189,12 +185,7 @@ public function _real_escape( $data ) {
189185
* or real_escape next.
190186
*/
191187
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;
188+
return parent::esc_like( $text );
198189
}
199190

200191
/**
@@ -326,34 +317,28 @@ public function db_connect( $allow_bail = true ) {
326317
}
327318
}
328319

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-
}
320+
if ( null === $this->dbname || '' === $this->dbname ) {
321+
$this->bail(
322+
'The database name was not set. The SQLite driver requires a database name to be set to emulate MySQL information schema tables.',
323+
'db_connect_fail'
324+
);
325+
return false;
326+
}
337327

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();
328+
$this->ensure_database_directory( FQDB );
329+
330+
try {
331+
$connection = new WP_SQLite_Connection(
332+
array(
333+
'pdo' => $pdo,
334+
'path' => FQDB,
335+
'journal_mode' => defined( 'SQLITE_JOURNAL_MODE' ) ? SQLITE_JOURNAL_MODE : null,
336+
)
337+
);
338+
$this->dbh = new WP_SQLite_Driver( $connection, $this->dbname );
339+
$GLOBALS['@pdo'] = $this->dbh->get_connection()->get_pdo();
340+
} catch ( Throwable $e ) {
341+
$this->last_error = $this->format_error_message( $e );
357342
}
358343
if ( $this->last_error ) {
359344
return false;
@@ -467,11 +452,7 @@ public function query( $query ) {
467452
if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {
468453
$return_val = true;
469454
} 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-
}
455+
$this->rows_affected = $this->dbh->get_last_return_value();
475456

476457
// Take note of the insert_id.
477458
if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
@@ -516,11 +497,7 @@ public function query( $query ) {
516497
}
517498

518499
// 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-
}
500+
$this->queries[ $i ]['sqlite_queries'] = $this->dbh->get_last_sqlite_queries();
524501
}
525502
return $return_val;
526503
}
@@ -545,10 +522,6 @@ private function _do_query( $query ) {
545522
$this->last_error = $this->format_error_message( $e );
546523
}
547524

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

554527
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
@@ -573,27 +546,23 @@ protected function load_col_info() {
573546
if ( $this->col_info ) {
574547
return;
575548
}
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();
549+
$this->col_info = array();
550+
foreach ( $this->dbh->get_last_column_meta() as $column ) {
551+
$this->col_info[] = (object) array(
552+
'name' => $column['name'],
553+
'orgname' => $column['mysqli:orgname'],
554+
'table' => $column['table'],
555+
'orgtable' => $column['mysqli:orgtable'],
556+
'def' => '', // Unused, always ''.
557+
'db' => $column['mysqli:db'],
558+
'catalog' => 'def', // Unused, always 'def'.
559+
'max_length' => 0, // As of PHP 8.1, this is always 0.
560+
'length' => $column['len'],
561+
'charsetnr' => $column['mysqli:charsetnr'],
562+
'flags' => $column['mysqli:flags'],
563+
'type' => $column['mysqli:type'],
564+
'decimals' => $column['precision'],
565+
);
597566
}
598567
}
599568

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: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ 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-
}
37+
$translator = new WP_SQLite_Driver(
38+
new WP_SQLite_Connection( array( 'pdo' => $pdo ) ),
39+
$wpdb->dbname
40+
);
4541
$query = null;
4642

4743
try {

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)