File tree Expand file tree Collapse file tree 2 files changed +41
-10
lines changed Expand file tree Collapse file tree 2 files changed +41
-10
lines changed Original file line number Diff line number Diff line change @@ -208,22 +208,27 @@ impl MySqlConnection {
208
208
loop {
209
209
let packet = self . inner. stream. recv_packet( ) . await ?;
210
210
211
- if packet[ 0 ] == 0xfe && packet. len( ) < 9 {
212
- let eof = packet. eof( self . inner. stream. capabilities) ?;
213
-
214
- self . inner. status_flags = eof. status;
215
-
211
+ if packet[ 0 ] == 0xfe {
212
+ let ( rows_affected, last_insert_id, status) = if packet. len( ) < 9 {
213
+ // EOF packet
214
+ let eof = packet. eof( self . inner. stream. capabilities) ?;
215
+ ( 0 , 0 , eof. status)
216
+ } else {
217
+ // OK packet
218
+ let ok = packet. ok( ) ?;
219
+ ( ok. affected_rows, ok. last_insert_id, ok. status)
220
+ } ;
221
+
222
+ self . inner. status_flags = status;
216
223
r#yield!( Either :: Left ( MySqlQueryResult {
217
- rows_affected: 0 ,
218
- last_insert_id: 0 ,
224
+ rows_affected,
225
+ last_insert_id,
219
226
} ) ) ;
220
227
221
- if eof. status. contains( Status :: SERVER_MORE_RESULTS_EXISTS ) {
222
- // more result sets exist, continue to the next one
228
+ if status. contains( Status :: SERVER_MORE_RESULTS_EXISTS ) {
223
229
* self . inner. stream. waiting. front_mut( ) . unwrap( ) = Waiting :: Result ;
224
230
break ;
225
231
}
226
-
227
232
self . inner. stream. waiting. pop_front( ) ;
228
233
return Ok ( ( ) ) ;
229
234
}
Original file line number Diff line number Diff line change @@ -50,3 +50,29 @@ fn test_decode_ok_packet() {
50
50
assert ! ( p. status. contains( Status :: SERVER_STATUS_AUTOCOMMIT ) ) ;
51
51
assert ! ( p. status. contains( Status :: SERVER_SESSION_STATE_CHANGED ) ) ;
52
52
}
53
+
54
+ #[ test]
55
+ fn test_decode_ok_packet_with_info ( ) {
56
+ // OK packet with 0xfe header and length >= 9 (with appended info)
57
+ const DATA : & [ u8 ] = b"\xfe \x01 \x00 \x02 \x00 \x00 \x00 \x05 \x09 info data" ;
58
+
59
+ let p = OkPacket :: decode ( DATA . into ( ) ) . unwrap ( ) ;
60
+
61
+ assert_eq ! ( p. affected_rows, 1 ) ;
62
+ assert_eq ! ( p. last_insert_id, 0 ) ;
63
+ assert_eq ! ( p. warnings, 0 ) ;
64
+ assert ! ( p. status. contains( Status :: SERVER_STATUS_AUTOCOMMIT ) ) ;
65
+ }
66
+
67
+ #[ test]
68
+ fn test_decode_ok_packet_with_extended_info ( ) {
69
+ // OK packet with 0xfe header, affected rows, last insert id, and extended info
70
+ const DATA : & [ u8 ] = b"\xfe \x05 \x64 \x02 \x00 \x01 \x00 \x0e \x14 extended information" ;
71
+
72
+ let p = OkPacket :: decode ( DATA . into ( ) ) . unwrap ( ) ;
73
+
74
+ assert_eq ! ( p. affected_rows, 5 ) ;
75
+ assert_eq ! ( p. last_insert_id, 100 ) ;
76
+ assert_eq ! ( p. warnings, 1 ) ;
77
+ assert ! ( p. status. contains( Status :: SERVER_STATUS_AUTOCOMMIT ) ) ;
78
+ }
You can’t perform that action at this time.
0 commit comments