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

Commit ad198eb

Browse files
committed
Use correct PDO exception and code when table not found
1 parent 802a725 commit ad198eb

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
<?php
22

3-
class WP_SQLite_Driver_Exception extends Exception {
3+
class WP_SQLite_Driver_Exception extends PDOException {
44
/**
55
* The SQLite driver that originated the exception.
66
*
77
* @var WP_SQLite_Driver
88
*/
99
private $driver;
1010

11+
/**
12+
* Constructor.
13+
*
14+
* @param WP_SQLite_Driver $driver The 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+
*/
1119
public function __construct(
1220
WP_SQLite_Driver $driver,
1321
string $message,
14-
int $code = 0,
22+
$code = 0,
1523
Throwable $previous = null
1624
) {
17-
parent::__construct( $message, $code, $previous );
25+
parent::__construct( $message, 0, $previous );
26+
$this->code = $code;
1827
$this->driver = $driver;
1928
}
2029

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,8 @@ private function get_sqlite_create_table_statement( string $table_name, ?string
24992499

25002500
if ( false === $table_info ) {
25012501
throw $this->new_driver_exception(
2502-
sprintf( 'Table "%s" not found in information schema', $table_name )
2502+
sprintf( "Table '%s' doesn't exist", $table_name ),
2503+
'42S02'
25032504
);
25042505
}
25052506

@@ -2909,13 +2910,13 @@ private function set_result_from_affected_rows( int $override = null ): void {
29092910
* Create a new SQLite driver exception.
29102911
*
29112912
* @param string $message The exception message.
2912-
* @param int $code The exception code.
2913+
* @param int|string $code The exception code. For PDO errors, a string representing SQLSTATE.
29132914
* @param Throwable|null $previous The previous exception.
29142915
* @return WP_SQLite_Driver_Exception
29152916
*/
29162917
private function new_driver_exception(
29172918
string $message,
2918-
int $code = 0,
2919+
$code = 0,
29192920
Throwable $previous = null
29202921
): WP_SQLite_Driver_Exception {
29212922
return new WP_SQLite_Driver_Exception( $this, $message, $code, $previous );

0 commit comments

Comments
 (0)