Skip to content

Commit da1cee9

Browse files
committed
Rename the driver exception
Align the exception class with the WP_MySQL_On_SQLite API name. Do not retain the obsolete class name because no external runtime usage was found.
1 parent 48574a3 commit da1cee9

10 files changed

Lines changed: 161 additions & 155 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
require_once __DIR__ . '/sqlite/class-wp-sqlite-connection.php';
3737
require_once __DIR__ . '/sqlite/class-wp-sqlite-configurator.php';
3838
require_once __DIR__ . '/sqlite/class-wp-sqlite-driver.php';
39-
require_once __DIR__ . '/sqlite/class-wp-sqlite-driver-exception.php';
39+
require_once __DIR__ . '/sqlite/class-wp-mysql-on-sqlite-exception.php';
4040
require_once __DIR__ . '/sqlite/class-wp-sqlite-information-schema-builder.php';
4141
require_once __DIR__ . '/sqlite/class-wp-sqlite-information-schema-exception.php';
4242
require_once __DIR__ . '/sqlite/class-wp-sqlite-information-schema-reconstructor.php';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
class WP_MySQL_On_SQLite_Exception extends PDOException {
4+
/**
5+
* The MySQL-on-SQLite driver that originated the exception.
6+
*
7+
* @var WP_MySQL_On_SQLite
8+
*/
9+
private $driver;
10+
11+
/**
12+
* Constructor.
13+
*
14+
* @param WP_MySQL_On_SQLite $driver The MySQL-on-SQLite driver that originated the exception.
15+
* @param string $message The exception message.
16+
* @param int|string $code The exception code. In PDO, it can be a string with value of SQLSTATE.
17+
* @param Throwable|null $previous The previous throwable used for the exception chaining.
18+
*/
19+
public function __construct(
20+
WP_MySQL_On_SQLite $driver,
21+
string $message,
22+
$code = 0,
23+
?Throwable $previous = null
24+
) {
25+
parent::__construct( $message, 0, $previous );
26+
$this->code = $code;
27+
$this->driver = $driver;
28+
}
29+
30+
public function get_driver(): WP_MySQL_On_SQLite {
31+
return $this->driver;
32+
}
33+
}

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

Lines changed: 51 additions & 51 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class WP_SQLite_Driver {
6060
* @param string $database The database name.
6161
* @param int $mysql_version The emulated MySQL version as an integer.
6262
*
63-
* @throws WP_SQLite_Driver_Exception When the driver initialization fails.
63+
* @throws WP_MySQL_On_SQLite_Exception When the driver initialization fails.
6464
*/
6565
public function __construct(
6666
WP_SQLite_Connection $connection,
@@ -157,7 +157,7 @@ public function get_insert_id() {
157157
*
158158
* @return mixed Return value, depending on the query type.
159159
*
160-
* @throws WP_SQLite_Driver_Exception When the query execution fails.
160+
* @throws WP_MySQL_On_SQLite_Exception When the query execution fails.
161161
*/
162162
public function query( string $query, $fetch_mode = PDO::FETCH_OBJ, ...$fetch_mode_args ) {
163163
$stmt = $this->mysql_on_sqlite_driver->query( $query, $fetch_mode, ...$fetch_mode_args );

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function ensure_correct_information_schema(): void {
7878
$sql = $this->generate_create_table_statement( $table );
7979
$ast = $this->driver->create_parser( $sql )->parse();
8080
if ( null === $ast ) {
81-
throw new WP_SQLite_Driver_Exception( $this->driver, 'Failed to parse the MySQL query.' );
81+
throw new WP_MySQL_On_SQLite_Exception( $this->driver, 'Failed to parse the MySQL query.' );
8282
}
8383
}
8484

@@ -113,7 +113,7 @@ private function record_drop_table( string $table_name ): void {
113113
$sql = sprintf( 'DROP TABLE %s', $this->connection->quote_identifier( $table_name ) ); // TODO: mysql quote
114114
$ast = $this->driver->create_parser( $sql )->parse();
115115
if ( null === $ast ) {
116-
throw new WP_SQLite_Driver_Exception( $this->driver, 'Failed to parse the MySQL query.' );
116+
throw new WP_MySQL_On_SQLite_Exception( $this->driver, 'Failed to parse the MySQL query.' );
117117
}
118118
$this->schema_builder->record_drop_table(
119119
$ast->get_first_descendant_node( 'dropStatement' )
@@ -235,7 +235,7 @@ private function get_wp_create_table_statements(): array {
235235
while ( $parser->next_query() ) {
236236
$ast = $parser->get_query_ast();
237237
if ( null === $ast ) {
238-
throw new WP_SQLite_Driver_Exception( $this->driver, 'Failed to parse the MySQL query.' );
238+
throw new WP_MySQL_On_SQLite_Exception( $this->driver, 'Failed to parse the MySQL query.' );
239239
}
240240

241241
$create_node = $ast->get_first_descendant_node( 'createStatement' );

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ public function testInformationSchemaAlterTableDropConstraint(): void {
22912291
public function testInformationSchemaAlterTableDropMissingConstraint(): void {
22922292
$this->assertQuery( 'CREATE TABLE t1 (id INT PRIMARY KEY)' );
22932293

2294-
$this->expectException( WP_SQLite_Driver_Exception::class );
2294+
$this->expectException( WP_MySQL_On_SQLite_Exception::class );
22952295
$this->expectExceptionMessage( "SQLSTATE[HY000]: General error: 3940 Constraint 'cnst' does not exist." );
22962296
$this->expectExceptionCode( 'HY000' );
22972297
$this->assertQuery( 'ALTER TABLE t2 DROP CONSTRAINT cnst' );
@@ -2307,7 +2307,7 @@ public function testInformationSchemaAlterTableDropConstraintWithAmbiguousName()
23072307
)'
23082308
);
23092309

2310-
$this->expectException( WP_SQLite_Driver_Exception::class );
2310+
$this->expectException( WP_MySQL_On_SQLite_Exception::class );
23112311
$this->expectExceptionMessage( "SQLSTATE[HY000]: General error: 3939 Table has multiple constraints with the name 'cnst'. Please use constraint specific 'DROP' clause." );
23122312
$this->expectExceptionCode( 'HY000' );
23132313
$this->assertQuery( 'ALTER TABLE t2 DROP CONSTRAINT cnst' );

‎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
@@ -34,6 +34,12 @@ public function test_connection(): void {
3434
$this->assertInstanceOf( PDO::class, $driver );
3535
}
3636

37+
public function test_driver_exception_exposes_originating_driver(): void {
38+
$exception = new WP_MySQL_On_SQLite_Exception( $this->driver, 'Test error.' );
39+
40+
$this->assertSame( $this->driver, $exception->get_driver() );
41+
}
42+
3743
public function test_exposes_underlying_sqlite_pdo(): void {
3844
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
3945
$pdo = new $pdo_class( 'sqlite::memory:' );

0 commit comments

Comments
 (0)