From 3b36d8a4a8d27f8093e457b5e626d6ee0d28d7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 31 Jul 2026 16:35:31 +0200 Subject: [PATCH 01/10] Remove obsolete database engine alias Drop the DATABASE_ENGINE input alias now that DB_ENGINE is the supported configuration API. --- packages/plugin-sqlite-database-integration/constants.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/plugin-sqlite-database-integration/constants.php b/packages/plugin-sqlite-database-integration/constants.php index 15e6772a1..713bd3237 100644 --- a/packages/plugin-sqlite-database-integration/constants.php +++ b/packages/plugin-sqlite-database-integration/constants.php @@ -10,9 +10,6 @@ if ( ! defined( 'DB_ENGINE' ) ) { if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) { define( 'DB_ENGINE', 'sqlite' ); - } elseif ( defined( 'DATABASE_ENGINE' ) ) { - // backwards compatibility with previous versions of the plugin. - define( 'DB_ENGINE', DATABASE_ENGINE ); } else { define( 'DB_ENGINE', 'mysql' ); } From fc315e84103f6ebc9709fb64dce186896436e6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 31 Jul 2026 16:36:04 +0200 Subject: [PATCH 02/10] Remove obsolete crosscheck instrumentation Delete the broken development-only MySQL crosscheck path from the runtime plugin and its release contents. --- .gitattributes | 1 - .../sqlite/class-wp-sqlite-crosscheck-db.php | 127 ------------------ .../wp-includes/sqlite/db.php | 21 +-- .../wp-includes/sqlite/install-functions.php | 47 ------- phpcs.xml.dist | 1 - 5 files changed, 4 insertions(+), 193 deletions(-) delete mode 100644 packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php diff --git a/.gitattributes b/.gitattributes index 693ea9681..5b0cf7f1f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,5 +10,4 @@ wp-setup.sh export-ignore /grammar-tools export-ignore /packages export-ignore /tests export-ignore -/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php export-ignore /wordpress export-ignore diff --git a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php deleted file mode 100644 index 7878a4813..000000000 --- a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php +++ /dev/null @@ -1,127 +0,0 @@ -resetDatabases(); - } - - private function resetDatabases() { - if ( file_exists( FQDB ) ) { - unlink( FQDB ); - } - $GLOBALS['mysql']->query( 'DROP DATABASE IF EXISTS ' . DB_NAME ); - $GLOBALS['mysql']->query( 'CREATE DATABASE ' . DB_NAME ); - $GLOBALS['mysql']->query( 'USE ' . DB_NAME ); - } - - public function query( $query ) { - /** - * In MySQL, AUTO_INCREMENT columns don't reuse IDs assigned in rollback transactions - * In SQLite, AUTOINCREMENT columns do reuse IDs assigned in rollback transactions - * - * Let's store the current AUTOINCREMENT value for each table, and restore it afterwards. - */ - if ( preg_match( '/^\s*rollback/i', $query ) ) { - $autoincrements = array(); - $tables = $GLOBALS['@pdo']->query( "SELECT name as `table` FROM sqlite_master WHERE type='table' ORDER BY name" )->fetchAll(); - foreach ( $tables as $table ) { - $table = $table['table']; - $autoincrement = $GLOBALS['@pdo']->query( "SELECT seq FROM sqlite_sequence WHERE name = '$table'" )->fetchColumn(); - $autoincrements[ $table ] = $autoincrement ?: 1; - } - } - $sqlite_retval = parent::query( $query ); - if ( preg_match( '/^\s*rollback/i', $query ) ) { - foreach ( $autoincrements as $table => $autoincrement ) { - $GLOBALS['@pdo']->query( "UPDATE sqlite_sequence SET seq = $autoincrement WHERE name = '$table'" ); - } - } - $this->crosscheck( $query, $sqlite_retval ); - return $sqlite_retval; - } - - private function crosscheck( $query, $sqlite_retval ) { - // echo $query."\n\n"; - // Be lenient on cross-checking some query types - if ( preg_match( '/^\s*SET storage_engine/i', $query ) ) { - return; - } - $this->show_errors = false; - $this->suppress_errors = true; - $GLOBALS['mysql']->show_errors = false; - $GLOBALS['mysql']->suppress_errors = true; - - ob_start(); - $mysql_retval = $GLOBALS['mysql']->query( $query ); - ob_end_clean(); - - $tests = array( - array( 'retval', $mysql_retval, $sqlite_retval ), - array( 'num_rows', $GLOBALS['mysql']->num_rows, $GLOBALS['sqlite']->num_rows ), - array( 'insert_id', $GLOBALS['mysql']->insert_id, $GLOBALS['sqlite']->insert_id ), - array( 'rows_affected', $GLOBALS['mysql']->rows_affected, $GLOBALS['sqlite']->rows_affected ), - ); - - foreach ( $tests as $test ) { - list($factor, $mysql, $sqlite) = $test; - if ( $mysql !== $sqlite ) { - if ( 'insert_id' === $factor ) { - // On multi-inserts MySQL returns the first inserted ID - // while SQLite returns the last one. The cached insert_id - // value stays the same for a number of subsequent queries. - // Let's forgive this for now. - continue; - } - if ( 'rows_affected' === $factor && $mysql_retval === $mysql ) { - // SQLite doesn't provide the rowcount() functionality - continue; - } - if ( 'retval' === $factor && $GLOBALS['mysql']->rows_affected === $mysql ) { - // SQLite doesn't provide the rowcount() functionality - continue; - } - echo "======================================================\n"; - echo "======== *** $factor *** differed for query ========= \n"; - echo "======================================================\n"; - echo "MySQL query: \n"; - echo "$query\n\n"; - - echo "SQLite queries: \n"; - foreach ( $this->dbh->last_translation->queries as $query ) { - echo $query->sql . "\n"; - } - echo "\n"; - - $this->report_factor( - 'error', - $GLOBALS['mysql']->last_error, - $GLOBALS['sqlite']->last_error - ); - foreach ( $tests as $test ) { - $this->report_factor( - $test[0], - $test[1], - $test[2] - ); - } - // throw new Exception(); - break; - } - } - } - - private function report_factor( $factor, $mysql, $sqlite ) { - echo "$factor: \n"; - echo ' MySQL: ' . var_export( $mysql, true ) . "\n"; - echo ' SQLite: ' . var_export( $sqlite, true ) . "\n\n"; - } -} diff --git a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php index 033135152..7ede214af 100644 --- a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php +++ b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php @@ -51,21 +51,8 @@ require_once __DIR__ . '/class-wp-sqlite-db.php'; require_once __DIR__ . '/install-functions.php'; -$db_name = defined( 'DB_NAME' ) ? DB_NAME : ''; +$db_name = defined( 'DB_NAME' ) ? DB_NAME : ''; +$GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name ); -/* - * Debug: Cross-check with MySQL. - * This is for debugging purpose only and requires files - * that are present in the GitHub repository - * but not the plugin published on WordPress.org. - */ -$crosscheck_tests_file_path = __DIR__ . '/class-wp-sqlite-crosscheck-db.php'; -if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) { - require_once $crosscheck_tests_file_path; - $GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( $db_name ); -} else { - $GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name ); - - // Boot the Query Monitor plugin if it is active. - require_once __DIR__ . '/../../integrations/query-monitor/boot.php'; -} +// Boot the Query Monitor plugin if it is active. +require_once __DIR__ . '/../../integrations/query-monitor/boot.php'; diff --git a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/install-functions.php b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/install-functions.php index 89d1fc1ad..e849fe181 100644 --- a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/install-functions.php +++ b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/install-functions.php @@ -68,53 +68,6 @@ function sqlite_make_db_sqlite() { wp_die( $message, 'Database Error!' ); } - /* - * Debug: Cross-check with MySQL. - * This is for debugging purpose only and requires files - * that are present in the GitHub repository - * but not the plugin published on WordPress.org. - */ - if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK ) { - $host = DB_HOST; - $port = 3306; - if ( str_contains( $host, ':' ) ) { - $host_parts = explode( ':', $host ); - $host = $host_parts[0]; - $port = $host_parts[1]; - } - $dsn = 'mysql:host=' . $host . '; port=' . $port . '; dbname=' . DB_NAME; - $pdo_class = PHP_VERSION_ID >= 80400 ? PDO\MySQL::class : PDO::class; // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO - $pdo_mysql = new $pdo_class( $dsn, DB_USER, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO - $pdo_mysql->query( 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' ); - $pdo_mysql->query( 'SET time_zone = "+00:00";' ); - foreach ( $queries as $query ) { - $query = trim( $query ); - if ( empty( $query ) ) { - continue; - } - try { - $pdo_mysql->beginTransaction(); - $pdo_mysql->query( $query ); - } catch ( PDOException $err ) { - $err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - $err_code = $err_data[1]; - // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual - if ( 5 == $err_code || 6 == $err_code ) { - // If the database is locked, commit again. - $pdo_mysql->commit(); - } else { - $pdo_mysql->rollBack(); - $message = sprintf( - 'Error occurred while creating tables or indexes...
Query was: %s
', - var_export( $query, true ) - ); - $message .= sprintf( 'Error message is: %s', $err_data[2] ); - wp_die( $message, 'Database Error!' ); - } - } - } - } - return true; } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c7dd21335..19dfec077 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -34,7 +34,6 @@ /node_modules/* /build/* /wordpress/* - /packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-crosscheck-db.php