Skip to content

Commit 0aa38eb

Browse files
committed
Report emulated MySQL identity
Expose the MySQL PDO driver name while identifying the implementation as MySQL on SQLite through @@version_comment.
1 parent 902a032 commit 0aa38eb

5 files changed

Lines changed: 28 additions & 8 deletions

File tree

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ class WP_MySQL_On_SQLite extends PDO {
498498
private $mysql_version;
499499

500500
/**
501-
* The SQLite engine version.
501+
* The emulated MySQL client library version.
502502
*
503503
* This is a mysqli-like property that is needed to avoid a PHP warning in
504504
* the WordPress health info. The "WP_Debug_Data::get_wp_database()" method
@@ -930,8 +930,8 @@ function ( $key ) {
930930
}
931931
}
932932

933-
// Load SQLite version to a property used by WordPress health info.
934-
$this->client_info = $sqlite_version;
933+
// Load MySQL client information to a property used by WordPress health info.
934+
$this->client_info = $this->getAttribute( PDO::ATTR_CLIENT_VERSION );
935935

936936
// Enable foreign keys. By default, they are off.
937937
$this->connection->query( 'PRAGMA foreign_keys = ON' );
@@ -1444,7 +1444,9 @@ public function setAttribute( $attribute, $value ): bool {
14441444
*/
14451445
#[ReturnTypeWillChange]
14461446
public function getAttribute( $attribute ) {
1447-
if ( PDO::ATTR_CLIENT_VERSION === $attribute ) {
1447+
if ( PDO::ATTR_DRIVER_NAME === $attribute ) {
1448+
return 'mysql';
1449+
} elseif ( PDO::ATTR_CLIENT_VERSION === $attribute ) {
14481450
return 'mysqlnd ' . $this->get_mysql_server_version_string();
14491451
} elseif ( PDO::ATTR_SERVER_VERSION === $attribute ) {
14501452
return $this->get_mysql_server_version_string();
@@ -4320,7 +4322,7 @@ private function translate( $node ): ?string {
43204322
} elseif ( 'version' === $name ) {
43214323
$value = $this->get_mysql_server_version_string();
43224324
} elseif ( 'version_comment' === $name ) {
4323-
$value = 'MySQL Community Server - GPL';
4325+
$value = $this->get_mysql_server_version_comment();
43244326
} elseif ( WP_MySQL_Lexer::SESSION_SYMBOL === $type ) {
43254327
$value = $this->session_system_variables[ $name ] ?? null;
43264328
} else {
@@ -5128,6 +5130,15 @@ private function get_mysql_server_version_string(): string {
51285130
);
51295131
}
51305132

5133+
/**
5134+
* Get the comment identifying the emulated MySQL server implementation.
5135+
*
5136+
* @return string The MySQL server version comment.
5137+
*/
5138+
private function get_mysql_server_version_comment(): string {
5139+
return 'MySQL on SQLite';
5140+
}
5141+
51315142
/**
51325143
* Translate a MySQL datetime literal to SQLite.
51335144
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class WP_SQLite_Driver {
2727
/**
28-
* The SQLite engine version.
28+
* The emulated MySQL client library version.
2929
*
3030
* This is a mysqli-like property that is needed to avoid a PHP warning in
3131
* the WordPress health info. The "WP_Debug_Data::get_wp_database()" method

‎packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_PDO_API_Tests.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public function test_constructor_applies_pdo_options(): void {
101101
$this->assertSame( PDO::ERRMODE_EXCEPTION, $driver->get_sqlite_pdo()->getAttribute( PDO::ATTR_ERRMODE ) );
102102
}
103103

104+
public function test_reports_mysql_driver_name(): void {
105+
$this->assertSame( 'mysql', $this->driver->getAttribute( PDO::ATTR_DRIVER_NAME ) );
106+
$this->assertSame( 'sqlite', $this->driver->get_sqlite_pdo()->getAttribute( PDO::ATTR_DRIVER_NAME ) );
107+
}
108+
104109
public function test_configured_mysql_version_controls_reporting_and_parsing(): void {
105110
$driver = new WP_MySQL_On_SQLite(
106111
'mysql-on-sqlite:path=:memory:;dbname=WordPress;',
@@ -112,6 +117,7 @@ public function test_configured_mysql_version_controls_reporting_and_parsing():
112117

113118
$this->assertSame( $server_version, $driver->getAttribute( PDO::ATTR_SERVER_VERSION ) );
114119
$this->assertSame( 'mysqlnd ' . $server_version, $driver->getAttribute( PDO::ATTR_CLIENT_VERSION ) );
120+
$this->assertSame( 'mysqlnd ' . $server_version, $driver->client_info );
115121
$this->assertSame( $server_version, $driver->query( 'SELECT VERSION()' )->fetchColumn() );
116122
$this->assertSame( $server_version, $driver->query( 'SELECT @@version' )->fetchColumn() );
117123
$this->assertEquals( 1, $driver->query( 'SELECT 1 /*!80000 + 1 */' )->fetchColumn() );

‎packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7366,7 +7366,7 @@ public function testBuiltInSystemVariables(): void {
73667366
$this->assertSame( '8.0.38-mysql-on-sqlite-' . SQLITE_DRIVER_VERSION, $result[0]->{'@@version'} );
73677367

73687368
$result = $this->assertQuery( 'SELECT @@version_comment' );
7369-
$this->assertSame( 'MySQL Community Server - GPL', $result[0]->{'@@version_comment'} );
7369+
$this->assertSame( 'MySQL on SQLite', $result[0]->{'@@version_comment'} );
73707370
}
73717371

73727372
public function testSessionSystemVariables(): void {

‎packages/mysql-on-sqlite/tests/WP_SQLite_Driver_Compatibility_Tests.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ function () {
3333
$this->assertInstanceOf( WP_MySQL_On_SQLite::class, $mysql_on_sqlite_driver );
3434
$this->assertTrue( $mysql_on_sqlite_driver->getAttribute( PDO::ATTR_STRINGIFY_FETCHES ) );
3535
$this->assertSame( $this->sqlite, $this->driver->get_connection()->get_pdo() );
36-
$this->assertSame( $this->driver->get_sqlite_version(), $this->driver->client_info );
36+
$this->assertSame(
37+
'mysqlnd 8.0.38-mysql-on-sqlite-' . SQLITE_DRIVER_VERSION,
38+
$this->driver->client_info
39+
);
3740
$this->assertSame( SQLITE_DRIVER_VERSION, $this->driver->get_saved_driver_version() );
3841
$this->assertTrue( $this->driver->is_sql_mode_active( 'STRICT_TRANS_TABLES' ) );
3942
}

0 commit comments

Comments
 (0)