Skip to content
This repository was archived by the owner on Sep 11, 2026. It is now read-only.

Commit a22540e

Browse files
authored
Merge pull request #4 from WordPress/trunk
sync trunk
2 parents 2d0dbc0 + 2f49fd5 commit a22540e

28 files changed

Lines changed: 628 additions & 417 deletions

‎.github/workflows/wp-tests-phpunit-native-extension-setup.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ if ( ! ( $parser_ast instanceof WP_MySQL_Native_Parser_Node ) ) {
149149
wp_sqlite_native_parser_verification_fail( 'Native parser did not produce a native-backed AST in the WordPress PHP test container.' );
150150
}
151151
152-
$driver = new WP_PDO_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;' );
152+
$driver = new WP_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;' );
153153
$parser = $driver->create_parser( 'SELECT 1' );
154154
wp_sqlite_assert_native_parser_delegate( $parser, 'WordPress PHP test container SQLite driver did not create a native parser delegate.' );
155155
$parser->next_query();

‎.github/workflows/wp-tests-phpunit-run.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ const expectedErrors = [
1717
];
1818

1919
const expectedFailures = [
20-
'Tests_Admin_wpSiteHealth::test_object_cache_thresholds with data set #2',
2120
'Tests_Admin_wpSiteHealth::test_object_cache_thresholds with data set #3',
2221
'Tests_Comment::test_wp_new_comment_respects_comment_field_lengths',
2322
'Tests_Comment::test_wp_update_comment',
23+
'Tests_Comment_CheckComment::test_should_return_false_when_comment_previously_approved_is_enabled_and_author_does_not_have_approved_comment',
24+
'Tests_Comment_CheckComment::test_should_return_true_when_comment_previously_approved_is_enabled_and_author_has_approved_comment',
25+
'Tests_Comment_CheckComment::test_should_return_false_when_comment_previously_approved_is_enabled_and_user_does_not_have_a_previously_approved_comment_with_any_email',
2426
'Tests_DB_Charset::test_get_column_charset with data set #0',
2527
'Tests_DB_Charset::test_get_column_charset with data set #1',
2628
'Tests_DB_Charset::test_get_column_charset with data set #2',
@@ -87,7 +89,6 @@ const expectedFailures = [
8789
'Tests_Menu_Walker_Nav_Menu::test_start_el_with_empty_attributes with data set #6',
8890
'Tests_Menu_Walker_Nav_Menu::test_start_el_with_empty_attributes with data set #7',
8991
'Tests_Menu_wpNavMenu::test_wp_nav_menu_should_not_have_has_children_class_with_custom_depth',
90-
'WP_Test_REST_Posts_Controller::test_get_items_orderby_modified_query',
9192
];
9293

9394
console.log( 'Running WordPress PHPUnit tests with expected failures tracking...' );

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"wp-test-ensure-env": [
6363
"if [ ! -f wordpress/src/wp-load.php ]; then composer run wp-setup; fi",
6464
"@putenv COMPOSE_IGNORE_ORPHANS=true",
65-
"cd wordpress && if [ -z \"$(node tools/local-env/scripts/docker.js ps -q)\" ]; then cd ..; composer run wp-test-start; fi"
65+
"cd wordpress && if [ -z \"$(DOTENV_CONFIG_QUIET=true node tools/local-env/scripts/docker.js ps -q)\" ]; then cd ..; composer run wp-test-start; fi"
6666
],
6767
"wp-test-php": [
6868
"@wp-test-ensure-env @no_additional_args",

‎packages/mysql-on-sqlite/src/load.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@
4141
require_once __DIR__ . '/sqlite/class-wp-sqlite-information-schema-exception.php';
4242
require_once __DIR__ . '/sqlite/class-wp-sqlite-information-schema-reconstructor.php';
4343
require_once __DIR__ . '/sqlite/class-wp-sqlite-pdo-user-defined-functions.php';
44-
require_once __DIR__ . '/sqlite/class-wp-pdo-mysql-on-sqlite.php';
44+
require_once __DIR__ . '/sqlite/class-wp-mysql-on-sqlite.php';
4545
require_once __DIR__ . '/sqlite/class-wp-pdo-proxy-statement.php';

packages/mysql-on-sqlite/src/sqlite/class-wp-pdo-mysql-on-sqlite.php renamed to packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* The driver requires PDO with the SQLite driver, and the PCRE engine.
1616
*/
17-
class WP_PDO_MySQL_On_SQLite extends PDO {
17+
class WP_MySQL_On_SQLite extends PDO {
1818
/**
1919
* The path to the MySQL SQL grammar file.
2020
*/
@@ -632,8 +632,17 @@ class WP_PDO_MySQL_On_SQLite extends PDO {
632632
*
633633
* Set up an SQLite connection and the MySQL-on-SQLite driver.
634634
*
635-
* @param WP_SQLite_Connection $connection A SQLite database connection.
636-
* @param string $db_name The database name.
635+
* @param string $dsn MySQL-on-SQLite DSN containing the SQLite path and database name.
636+
* @param string|null $username Optional. Ignored by this driver.
637+
* @param string|null $password Optional. Ignored by this driver.
638+
* @param array $options {
639+
* Optional driver options.
640+
*
641+
* @type int $mysql_version Optional. MySQL version to emulate. Default 80038.
642+
* @type PDO|null $pdo Optional. Existing SQLite PDO connection.
643+
* @type string|null $journal_mode Optional. SQLite journal mode. Default 'WAL'.
644+
* @type string|int|null $synchronous Optional. SQLite synchronous setting.
645+
* }
637646
*
638647
* @throws WP_SQLite_Driver_Exception When the driver initialization fails.
639648
*/
@@ -789,11 +798,12 @@ function ( string $sql, array $params ) {
789798
*
790799
* A single MySQL query can be translated into zero or more SQLite queries.
791800
*
792-
* @param string $query Full SQL statement string.
793-
* @param int $fetch_mode PDO fetch mode. Default is PDO::FETCH_OBJ.
794-
* @param array ...$fetch_mode_args Additional fetch mode arguments.
801+
* @param string $query Full SQL statement string.
802+
* @param int|null $fetch_mode Optional. PDO fetch mode. Defaults to the configured
803+
* PDO::ATTR_DEFAULT_FETCH_MODE.
804+
* @param mixed ...$fetch_mode_args Additional fetch mode arguments.
795805
*
796-
* @return mixed Return value, depending on the query type.
806+
* @return PDOStatement|false PDO statement, or false when the fetch mode is invalid on PHP < 8.1.
797807
*
798808
* @throws WP_SQLite_Driver_Exception When the query execution fails.
799809
*/
@@ -1013,15 +1023,6 @@ public function beginTransaction(): bool {
10131023
return true;
10141024
}
10151025

1016-
/**
1017-
* A temporary alias for back compatibility.
1018-
*
1019-
* @see self::beginTransaction()
1020-
*/
1021-
public function begin_transaction(): void {
1022-
$this->beginTransaction();
1023-
}
1024-
10251026
/**
10261027
* PDO API: Commit a transaction.
10271028
*
@@ -4073,10 +4074,10 @@ private function translate_string_literal( WP_Parser_Node $node ): string {
40734074
/*
40744075
* Translate datetime literals.
40754076
*
4076-
* Process only strings that could possibly represent a datetime
4077-
* literal ("YYYY-MM-DDTHH:MM:SS", "YYYY-MM-DDTHH:MM:SSZ", etc.).
4077+
* Process only strings that could possibly represent a date or datetime
4078+
* literal ("YYYY-M-D", "YYYY-MM-DDTHH:MM:SSZ", etc.).
40784079
*/
4079-
if ( strlen( $value ) >= 19 && is_numeric( $value[0] ) ) {
4080+
if ( strlen( $value ) >= 8 && is_numeric( $value[0] ) ) {
40804081
$value = $this->translate_datetime_literal( $value );
40814082
}
40824083

@@ -4211,7 +4212,7 @@ private function translate_query_expression( WP_Parser_Node $node ): string {
42114212
* When the ORDER BY clause is present, we need to disambiguate the item
42124213
* list and make sure they don't cause an "ambiguous column name" error.
42134214
*
4214-
* @see WP_SQLite_Driver::disambiguate_item()
4215+
* @see WP_MySQL_On_SQLite::disambiguate_item()
42154216
*/
42164217
$disambiguated_order_list = array();
42174218
$order_clause = $node->get_first_child_node( 'orderClause' );
@@ -4279,7 +4280,7 @@ private function translate_query_specification( WP_Parser_Node $node ): string {
42794280
* When the GROUP BY or HAVING clause is present, we need to disambiguate
42804281
* the items to ensure they don't cause an "ambiguous column name" error.
42814282
*
4282-
* @see WP_SQLite_Driver::disambiguate_item()
4283+
* @see WP_MySQL_On_SQLite::disambiguate_item()
42834284
*/
42844285
$group_by_clause = null;
42854286
$having_clause = null;
@@ -4681,7 +4682,11 @@ private function translate_function_call( WP_Parser_Node $node ): string {
46814682
*/
46824683
private function translate_datetime_literal( string $value ): string {
46834684
/*
4684-
* The code below converts the date format to one preferred by SQLite.
4685+
* Normalize MySQL date and datetime literals for SQLite.
4686+
*
4687+
* MySQL accepts date and time components without zero padding. SQLite
4688+
* stores temporal values as text, so they must be normalized for lexical
4689+
* comparisons and SQLite date functions to work correctly.
46854690
*
46864691
* MySQL accepts ISO 8601 date strings: 'YYYY-MM-DDTHH:MM:SSZ'
46874692
* SQLite prefers a slightly different format: 'YYYY-MM-DD HH:MM:SS'
@@ -4704,8 +4709,25 @@ private function translate_datetime_literal( string $value ): string {
47044709
* which is true in the unit test suite, but there could also be a timezone offset
47054710
* like "+00:00" or "+01:00". We could add support for that later if needed.
47064711
*/
4707-
if ( 1 === preg_match( '/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})Z$/', $value, $matches ) ) {
4708-
$value = $matches[1] . ' ' . $matches[2];
4712+
if (
4713+
1 === preg_match(
4714+
'/^(\d{4})-(\d{1,2})-(\d{1,2})(?:([ T])(\d{1,2}):(\d{1,2}):(\d{1,2})(Z)?)?$/',
4715+
$value,
4716+
$matches
4717+
)
4718+
) {
4719+
$value = sprintf( '%04d-%02d-%02d', $matches[1], $matches[2], $matches[3] );
4720+
if ( isset( $matches[4] ) && '' !== $matches[4] ) {
4721+
$is_iso_8601 = 'T' === $matches[4] && 'Z' === ( $matches[8] ?? '' );
4722+
$value .= sprintf(
4723+
'%s%02d:%02d:%02d%s',
4724+
$is_iso_8601 ? ' ' : $matches[4],
4725+
$matches[5],
4726+
$matches[6],
4727+
$matches[7],
4728+
$is_iso_8601 ? '' : ( $matches[8] ?? '' )
4729+
);
4730+
}
47094731
}
47104732

47114733
/*
@@ -5767,7 +5789,7 @@ private function unnest_parenthesized_expression( WP_Parser_Node $node ): WP_Par
57675789
* consider column references in forms like "db.table.column".
57685790
*
57695791
* @param array $disambiguation_map The SELECT item disambiguation map (column name => array of select items).
5770-
* @see WP_SQLite_Driver::create_select_item_disambiguation_map()
5792+
* @see WP_MySQL_On_SQLite::create_select_item_disambiguation_map()
57715793
* @param WP_Parser_Node $expr The expression AST node or subnode.
57725794
* @return string|null The disambiguated and translated expression;
57735795
* null when the expression cannot be disambiguated.
@@ -5806,7 +5828,7 @@ private function disambiguate_item( array $disambiguation_map, WP_Parser_Node $e
58065828
* Create a SELECT item disambiguation map from a SELECT item list for use
58075829
* with the ORDER BY, GROUP BY, and HAVING clause disambiguation algorithm.
58085830
*
5809-
* @see WP_SQLite_Driver::disambiguate_item()
5831+
* @see WP_MySQL_On_SQLite::disambiguate_item()
58105832
*
58115833
* @param WP_Parser_Node $select_item_list The "selectItemList" AST node.
58125834
* @return array The SELECT item disambiguation map (column name => array of select items).

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-configurator.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class WP_SQLite_Configurator {
1414
/**
1515
* The SQLite driver instance.
1616
*
17-
* @var WP_PDO_MySQL_On_SQLite
17+
* @var WP_MySQL_On_SQLite
1818
*/
1919
private $driver;
2020

@@ -35,11 +35,11 @@ class WP_SQLite_Configurator {
3535
/**
3636
* Constructor.
3737
*
38-
* @param WP_PDO_MySQL_On_SQLite $driver The SQLite driver instance.
38+
* @param WP_MySQL_On_SQLite $driver The SQLite driver instance.
3939
* @param WP_SQLite_Information_Schema_Builder $schema_builder The information schema builder instance.
4040
*/
4141
public function __construct(
42-
WP_PDO_MySQL_On_SQLite $driver,
42+
WP_MySQL_On_SQLite $driver,
4343
WP_SQLite_Information_Schema_Builder $schema_builder
4444
) {
4545
$this->driver = $driver;
@@ -100,7 +100,7 @@ private function ensure_global_variables_table(): void {
100100
sprintf(
101101
'CREATE TABLE IF NOT EXISTS %s (name TEXT PRIMARY KEY, value TEXT)',
102102
$this->driver->get_connection()->quote_identifier(
103-
WP_PDO_MySQL_On_SQLite::GLOBAL_VARIABLES_TABLE_NAME
103+
WP_MySQL_On_SQLite::GLOBAL_VARIABLES_TABLE_NAME
104104
)
105105
)
106106
);
@@ -260,11 +260,11 @@ private function save_current_driver_version(): void {
260260
sprintf(
261261
'INSERT INTO %s (name, value) VALUES (?, ?) ON CONFLICT(name) DO UPDATE SET value = ?',
262262
$this->driver->get_connection()->quote_identifier(
263-
WP_PDO_MySQL_On_SQLite::GLOBAL_VARIABLES_TABLE_NAME
263+
WP_MySQL_On_SQLite::GLOBAL_VARIABLES_TABLE_NAME
264264
)
265265
),
266266
array(
267-
WP_PDO_MySQL_On_SQLite::DRIVER_VERSION_VARIABLE_NAME,
267+
WP_MySQL_On_SQLite::DRIVER_VERSION_VARIABLE_NAME,
268268
SQLITE_DRIVER_VERSION,
269269
SQLITE_DRIVER_VERSION,
270270
)

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-driver-exception.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ class WP_SQLite_Driver_Exception extends PDOException {
44
/**
55
* The SQLite driver that originated the exception.
66
*
7-
* @var WP_PDO_MySQL_On_SQLite
7+
* @var WP_MySQL_On_SQLite
88
*/
99
private $driver;
1010

1111
/**
1212
* Constructor.
1313
*
14-
* @param WP_PDO_MySQL_On_SQLite $driver The SQLite driver that originated the exception.
14+
* @param WP_MySQL_On_SQLite $driver The SQLite driver that originated the exception.
1515
* @param string $message The exception message.
1616
* @param int|string $code The exception code. In PDO, it can be a string with value of SQLSTATE.
1717
* @param Throwable|null $previous The previous throwable used for the exception chaining.
1818
*/
1919
public function __construct(
20-
WP_PDO_MySQL_On_SQLite $driver,
20+
WP_MySQL_On_SQLite $driver,
2121
string $message,
2222
$code = 0,
2323
?Throwable $previous = null
@@ -27,7 +27,7 @@ public function __construct(
2727
$this->driver = $driver;
2828
}
2929

30-
public function getDriver(): WP_PDO_MySQL_On_SQLite {
30+
public function getDriver(): WP_MySQL_On_SQLite {
3131
return $this->driver;
3232
}
3333
}

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-driver.php‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
/**
99
* For back compatibility with dependencies that use their own loader scripts
10-
* (e.g., WP CLI SQLite Command), ensure the new PDO-based classes are loaded.
10+
* (e.g., WP CLI SQLite Command), ensure the PDO-based classes are loaded.
1111
*/
12-
require_once __DIR__ . '/class-wp-pdo-mysql-on-sqlite.php';
12+
require_once __DIR__ . '/class-wp-mysql-on-sqlite.php';
1313
require_once __DIR__ . '/class-wp-pdo-proxy-statement.php';
1414

1515
/**
16-
* Deprecated: A proxy of the WP_PDO_MySQL_On_SQLite class preserving legacy API.
16+
* Deprecated: A proxy of the WP_MySQL_On_SQLite class preserving the legacy API.
1717
*
18-
* This is a temporary class to preserve the legacy API for easier transition
19-
* to the new PDO-based API, developed in the "WP_PDO_MySQL_On_SQLite" class.
18+
* This class temporarily preserves the legacy constructor and result API while
19+
* consumers transition to the PDO-based WP_MySQL_On_SQLite API.
2020
*/
2121
class WP_SQLite_Driver {
2222
/**
@@ -38,7 +38,7 @@ class WP_SQLite_Driver {
3838
/**
3939
* The MySQL-on-SQLite driver instance.
4040
*
41-
* @var WP_PDO_MySQL_On_SQLite
41+
* @var WP_MySQL_On_SQLite
4242
*/
4343
private $mysql_on_sqlite_driver;
4444

@@ -64,13 +64,14 @@ public function __construct(
6464
string $database,
6565
int $mysql_version = 80038
6666
) {
67-
$this->mysql_on_sqlite_driver = new WP_PDO_MySQL_On_SQLite(
67+
$this->mysql_on_sqlite_driver = new WP_MySQL_On_SQLite(
6868
sprintf( 'mysql-on-sqlite:dbname=%s', $database ),
6969
null,
7070
null,
7171
array(
7272
'mysql_version' => $mysql_version,
7373
'pdo' => $connection->get_pdo(),
74+
'journal_mode' => $connection->query( 'PRAGMA journal_mode' )->fetchColumn(),
7475
)
7576
);
7677
$this->main_db_name = $database;
@@ -229,7 +230,7 @@ public function execute_sqlite_query( string $sql, array $params = array() ): PD
229230
* Begin a new transaction or nested transaction.
230231
*/
231232
public function beginTransaction(): void { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
232-
$this->mysql_on_sqlite_driver->begin_transaction();
233+
$this->mysql_on_sqlite_driver->beginTransaction();
233234
}
234235

235236
/**

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-information-schema-reconstructor.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class WP_SQLite_Information_Schema_Reconstructor {
1919
/**
2020
* The SQLite driver instance.
2121
*
22-
* @var WP_PDO_MySQL_On_SQLite
22+
* @var WP_MySQL_On_SQLite
2323
*/
2424
private $driver;
2525

@@ -40,7 +40,7 @@ class WP_SQLite_Information_Schema_Reconstructor {
4040
/**
4141
* Constructor.
4242
*
43-
* @param WP_PDO_MySQL_On_SQLite $driver The SQLite driver instance.
43+
* @param WP_MySQL_On_SQLite $driver The SQLite driver instance.
4444
* @param WP_SQLite_Information_Schema_Builder $schema_builder The information schema builder instance.
4545
*/
4646
public function __construct(
@@ -137,7 +137,7 @@ private function get_sqlite_table_names(): array {
137137
array(
138138
'_mysql_data_types_cache',
139139
'sqlite\_%',
140-
str_replace( '_', '\_', WP_PDO_MySQL_On_SQLite::RESERVED_PREFIX ) . '%',
140+
str_replace( '_', '\_', WP_MySQL_On_SQLite::RESERVED_PREFIX ) . '%',
141141
)
142142
)->fetchAll( PDO::FETCH_COLUMN );
143143
}
@@ -763,9 +763,9 @@ private function get_mysql_column_type( string $column_type ): string {
763763
/**
764764
* Format a MySQL UTF-8 string literal for output in a CREATE TABLE statement.
765765
*
766-
* See WP_PDO_MySQL_On_SQLite::quote_mysql_utf8_string_literal().
766+
* See WP_MySQL_On_SQLite::quote_mysql_utf8_string_literal().
767767
*
768-
* TODO: This is a copy of WP_PDO_MySQL_On_SQLite::quote_mysql_utf8_string_literal().
768+
* TODO: This is a copy of WP_MySQL_On_SQLite::quote_mysql_utf8_string_literal().
769769
* We may consider extracing it to reusable MySQL helpers.
770770
*
771771
* @param string $utf8_literal The UTF-8 string literal to escape.

‎packages/mysql-on-sqlite/src/version.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*
66
* This constant needs to be updated on plugin release!
77
*/
8-
define( 'SQLITE_DRIVER_VERSION', '3.0.0-rc.6' );
8+
define( 'SQLITE_DRIVER_VERSION', '3.0.0-rc.7' );

0 commit comments

Comments
 (0)