11using System ;
2+ using System . Text ;
23using MySqlConnector . Protocol . Serialization ;
34using MySqlConnector . Utilities ;
45
56namespace MySqlConnector . Protocol . Payloads
67{
78 internal sealed class OkPayload
89 {
9- public int AffectedRowCount { get ; set ; }
10- public long LastInsertId { get ; set ; }
11- public ServerStatus ServerStatus { get ; set ; }
12- public int WarningCount { get ; set ; }
10+ public int AffectedRowCount { get ; }
11+ public long LastInsertId { get ; }
12+ public ServerStatus ServerStatus { get ; }
13+ public int WarningCount { get ; }
14+ public string NewSchema { get ; }
1315
1416 public const byte Signature = 0x00 ;
1517
@@ -35,16 +37,47 @@ public static OkPayload Create(PayloadData payload, bool deprecateEof)
3537 var lastInsertId = checked ( ( long ) reader . ReadLengthEncodedInteger ( ) ) ;
3638 var serverStatus = ( ServerStatus ) reader . ReadUInt16 ( ) ;
3739 var warningCount = ( int ) reader . ReadUInt16 ( ) ;
40+ string newSchema = null ;
3841
39- return new OkPayload ( affectedRowCount , lastInsertId , serverStatus , warningCount ) ;
42+ if ( ( serverStatus & ServerStatus . SessionStateChanged ) == ServerStatus . SessionStateChanged )
43+ {
44+ reader . ReadLengthEncodedByteString ( ) ; // human-readable info
45+
46+ // implies ProtocolCapabilities.SessionTrack
47+ var sessionStateChangeDataLength = checked ( ( int ) reader . ReadLengthEncodedInteger ( ) ) ;
48+ var endOffset = reader . Offset + sessionStateChangeDataLength ;
49+ while ( reader . Offset < endOffset )
50+ {
51+ var kind = ( SessionTrackKind ) reader . ReadByte ( ) ;
52+ var dataLength = ( int ) reader . ReadLengthEncodedInteger ( ) ;
53+ switch ( kind )
54+ {
55+ case SessionTrackKind . Schema :
56+ newSchema = Encoding . UTF8 . GetString ( reader . ReadLengthEncodedByteString ( ) ) ;
57+ break ;
58+
59+ default :
60+ reader . Offset += dataLength ;
61+ break ;
62+ }
63+ }
64+ }
65+ else
66+ {
67+ // either "string<EOF> info" or "string<lenenc> info" (followed by no session change info)
68+ // ignore human-readable string in both cases
69+ }
70+
71+ return new OkPayload ( affectedRowCount , lastInsertId , serverStatus , warningCount , newSchema ) ;
4072 }
4173
42- private OkPayload ( int affectedRowCount , long lastInsertId , ServerStatus serverStatus , int warningCount )
74+ private OkPayload ( int affectedRowCount , long lastInsertId , ServerStatus serverStatus , int warningCount , string newSchema )
4375 {
4476 AffectedRowCount = affectedRowCount ;
4577 LastInsertId = lastInsertId ;
4678 ServerStatus = serverStatus ;
4779 WarningCount = warningCount ;
80+ NewSchema = newSchema ;
4881 }
4982 }
5083}
0 commit comments