Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 487bf54

Browse files
committed
Use PDO to load SQLite version, improve docs
1 parent 069f1ef commit 487bf54

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ class WP_SQLite_Driver {
193193
'%y' => '%y',
194194
);
195195

196+
/**
197+
* The SQLite version.
198+
*
199+
* This is a mysqli-like property that is needed to avoid a PHP warning in
200+
* the WordPress health info. The "WP_Debug_Data::get_wp_database()" method
201+
* calls "$wpdb->dbh->client_info" - a mysqli-specific abstraction leak.
202+
*
203+
* @TODO: This should be fixed in WordPress core.
204+
*
205+
* See:
206+
* https://github.com/WordPress/wordpress-develop/blob/bcdca3f9925f1d3eca7b78d231837c0caf0c8c24/src/wp-admin/includes/class-wp-debug-data.php#L1579
207+
*
208+
* @var string
209+
*/
210+
public $client_info;
211+
196212
/**
197213
* @var WP_Parser_Grammar
198214
*/
@@ -214,15 +230,6 @@ class WP_SQLite_Driver {
214230
*/
215231
private $pdo;
216232

217-
/**
218-
* The database version.
219-
*
220-
* This is used here to avoid PHP warnings in the health screen.
221-
*
222-
* @var string
223-
*/
224-
public $client_info = '';
225-
226233
/**
227234
* Last executed MySQL query.
228235
*
@@ -434,11 +441,8 @@ public function __construct( string $db_name, ?PDO $pdo = null ) {
434441
self::$grammar = new WP_Parser_Grammar( require self::GRAMMAR_PATH );
435442
}
436443

437-
// Fixes a warning in the site-health screen.
438-
// @TODO: It is not clear how this fixes a warning or if it serves a
439-
// different purpose. We should also make this use PDO and
440-
// consider providing that information lazily via a getter.
441-
$this->client_info = SQLite3::version()['versionString'];
444+
// Load SQLite version to a property used by WordPress health info.
445+
$this->client_info = $this->get_sqlite_version();
442446

443447
$this->pdo->query( 'PRAGMA foreign_keys = ON' );
444448
$this->pdo->query( 'PRAGMA encoding="UTF-8";' );
@@ -458,6 +462,15 @@ public function get_pdo() {
458462
return $this->pdo;
459463
}
460464

465+
/**
466+
* Get the version of the SQLite engine.
467+
*
468+
* @return string SQLite engine version as a string.
469+
*/
470+
public function get_sqlite_version(): string {
471+
return $this->pdo->query( 'SELECT SQLITE_VERSION()' )->fetchColumn();
472+
}
473+
461474
/**
462475
* Method to return inserted row id.
463476
*/

wp-includes/sqlite/class-wp-sqlite-db.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ public function db_version() {
366366
}
367367

368368
/**
369-
* Retrieves full database server information.
369+
* Returns the version of the SQLite engine.
370370
*
371-
* @return string|false Server info on success, false on failure.
371+
* @return string SQLite engine version as a string.
372372
*/
373373
public function db_server_info() {
374-
return SQLite3::version()['versionString'];
374+
return $this->dbh->get_sqlite_version();
375375
}
376376
}

wp-includes/sqlite/class-wp-sqlite-translator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function __construct( $pdo = null ) {
410410
$this->pdo = $pdo;
411411

412412
// Fixes a warning in the site-health screen.
413-
$this->client_info = SQLite3::version()['versionString'];
413+
$this->client_info = $this->get_sqlite_version();
414414

415415
register_shutdown_function( array( $this, '__destruct' ) );
416416

@@ -474,6 +474,15 @@ public function get_pdo() {
474474
return $this->pdo;
475475
}
476476

477+
/**
478+
* Get the version of the SQLite engine.
479+
*
480+
* @return string SQLite engine version as a string.
481+
*/
482+
public function get_sqlite_version(): string {
483+
return $this->pdo->query( 'SELECT SQLITE_VERSION()' )->fetchColumn();
484+
}
485+
477486
/**
478487
* Method to return inserted row id.
479488
*/

0 commit comments

Comments
 (0)