Skip to content

Commit fe161ea

Browse files
committed
Default a result's last insert ID to 0
The OK packet builder requires an int, so a result built without an insert ID raised a TypeError that reached the client as an unknown error.
1 parent ee58fa6 commit fe161ea

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎packages/mysql-proxy/src/Adapter/class-sqlite-adapter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct( $sqlite_database_path ) {
2323

2424
public function handle_query( string $query ): MySQL_Result {
2525
$affected_rows = 0;
26-
$last_insert_id = null;
26+
$last_insert_id = 0;
2727
$columns = array();
2828
$rows = array();
2929

‎packages/mysql-proxy/src/class-mysql-result.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class MySQL_Result {
66
public $affected_rows = 0;
7-
public $last_insert_id = null;
7+
public $last_insert_id = 0;
88
public $columns = array();
99
public $rows = array();
1010

‎packages/mysql-proxy/tests/WP_MySQL_Session_Command_Test.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public function test_oversized_message_is_refused(): void {
8383
$this->assertFalse( $session->has_buffered_data() );
8484
}
8585

86+
public function test_result_without_an_insert_id_is_an_ok_packet(): void {
87+
$adapter = $this->createMock( Adapter::class );
88+
$adapter->expects( $this->once() )->method( 'handle_query' )->willReturn( new MySQL_Result() );
89+
$session = $this->authenticated_session( $adapter );
90+
$response = $session->receive_bytes( MySQL_Protocol::build_packet( 0, chr( MySQL_Protocol::COM_QUERY ) . 'DELETE FROM t' ) );
91+
$this->assertSame( 0, ord( $response[4] ) );
92+
$this->assertFalse( $session->is_closed() );
93+
}
94+
8695
public function test_empty_command_packet_is_refused(): void {
8796
$adapter = $this->createMock( Adapter::class );
8897
$adapter->expects( $this->never() )->method( 'handle_query' );

0 commit comments

Comments
 (0)