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

Commit 1dca9b6

Browse files
committed
Extract debug mode setting to an option
1 parent c199271 commit 1dca9b6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ class WP_SQLite_Driver {
232232
*/
233233
private $pdo;
234234

235+
/**
236+
* Enables debug mode.
237+
*
238+
* @var bool
239+
*/
240+
private $debug;
241+
235242
/**
236243
* Last executed MySQL query.
237244
*
@@ -323,6 +330,7 @@ class WP_SQLite_Driver {
323330
* Must be set when PDO instance is not provided.
324331
* @type PDO|null $connection Optional. PDO instance with SQLite connection.
325332
* If not provided, a new PDO instance will be created.
333+
* @type bool $debug Optional. Enable debug mode.
326334
* @type int|null $timeout Optional. SQLite timeout in seconds.
327335
* The time to wait for a writable lock.
328336
* @type string|null $sqlite_journal_mode Optional. SQLite journal mode.
@@ -340,6 +348,9 @@ public function __construct( array $options ) {
340348
$this->pdo = $options['connection'];
341349
}
342350

351+
// Debug mode.
352+
$this->debug = isset( $options['debug'] ) && true === $options['debug'];
353+
343354
// Create a PDO connection if it is not provided.
344355
if ( ! $this->pdo ) {
345356
if ( ! isset( $options['path'] ) || ! is_string( $options['path'] ) ) {
@@ -542,7 +553,7 @@ public function query( string $query, $fetch_mode = PDO::FETCH_OBJ, ...$fetch_mo
542553
} catch ( Throwable $rollback_exception ) {
543554
// Ignore rollback errors.
544555
}
545-
if ( defined( 'PDO_DEBUG' ) && PDO_DEBUG === true ) {
556+
if ( true === $this->debug ) {
546557
throw $e;
547558
}
548559
return $this->handle_error( $e );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public function db_connect( $allow_bail = true ) {
244244
$this->dbh = new WP_SQLite_Driver(
245245
array(
246246
'connection' => $pdo,
247+
'debug' => defined( 'PDO_DEBUG' ) && true === PDO_DEBUG,
247248
'path' => FQDB,
248249
'database' => $this->dbname,
249250
'sqlite_journal_mode' => SQLITE_JOURNAL_MODE,

0 commit comments

Comments
 (0)