@@ -14,8 +14,8 @@ internal sealed class OkPayload
14
14
public int WarningCount { get ; }
15
15
public string ? StatusInfo { get ; }
16
16
public string ? NewSchema { get ; }
17
- public string ? ClientCharacterSet { get ; }
18
- public int ? ConnectionId { get ; }
17
+ public CharacterSet ? NewCharacterSet { get ; }
18
+ public int ? NewConnectionId { get ; }
19
19
20
20
public const byte Signature = 0x00 ;
21
21
@@ -61,7 +61,9 @@ public static void Verify(ReadOnlySpan<byte> span, IServerCapabilities serverCap
61
61
var serverStatus = ( ServerStatus ) reader . ReadUInt16 ( ) ;
62
62
var warningCount = ( int ) reader . ReadUInt16 ( ) ;
63
63
string ? newSchema = null ;
64
- string ? clientCharacterSet = null ;
64
+ CharacterSet clientCharacterSet = default ;
65
+ CharacterSet connectionCharacterSet = default ;
66
+ CharacterSet resultsCharacterSet = default ;
65
67
int ? connectionId = null ;
66
68
ReadOnlySpan < byte > statusBytes ;
67
69
@@ -93,7 +95,21 @@ public static void Verify(ReadOnlySpan<byte> span, IServerCapabilities serverCap
93
95
var systemVariableValue = systemVariableValueLength == - 1 ? default : reader . ReadByteString ( systemVariableValueLength ) ;
94
96
if ( systemVariableName . SequenceEqual ( "character_set_client"u8 ) && systemVariableValueLength != 0 )
95
97
{
96
- clientCharacterSet = Encoding . ASCII . GetString ( systemVariableValue ) ;
98
+ clientCharacterSet = systemVariableValue . SequenceEqual ( "utf8mb4"u8 ) ? CharacterSet . Utf8Mb4Binary :
99
+ systemVariableValue . SequenceEqual ( "utf8"u8 ) ? CharacterSet . Utf8Mb3Binary :
100
+ CharacterSet . None ;
101
+ }
102
+ else if ( systemVariableName . SequenceEqual ( "character_set_connection"u8 ) && systemVariableValueLength != 0 )
103
+ {
104
+ connectionCharacterSet = systemVariableValue . SequenceEqual ( "utf8mb4"u8 ) ? CharacterSet . Utf8Mb4Binary :
105
+ systemVariableValue . SequenceEqual ( "utf8"u8 ) ? CharacterSet . Utf8Mb3Binary :
106
+ CharacterSet . None ;
107
+ }
108
+ else if ( systemVariableName . SequenceEqual ( "character_set_results"u8 ) && systemVariableValueLength != 0 )
109
+ {
110
+ resultsCharacterSet = systemVariableValue . SequenceEqual ( "utf8mb4"u8 ) ? CharacterSet . Utf8Mb4Binary :
111
+ systemVariableValue . SequenceEqual ( "utf8"u8 ) ? CharacterSet . Utf8Mb3Binary :
112
+ CharacterSet . None ;
97
113
}
98
114
else if ( systemVariableName . SequenceEqual ( "connection_id"u8 ) )
99
115
{
@@ -129,32 +145,37 @@ public static void Verify(ReadOnlySpan<byte> span, IServerCapabilities serverCap
129
145
{
130
146
var statusInfo = statusBytes . Length == 0 ? null : Encoding . UTF8 . GetString ( statusBytes ) ;
131
147
132
- if ( affectedRowCount == 0 && lastInsertId == 0 && warningCount == 0 && statusInfo is null && newSchema is null && clientCharacterSet is null && connectionId is null )
148
+ // detect the connection character set as utf8mb4 (or utf8) if all three system variables are set to the same value
149
+ var characterSet = clientCharacterSet == CharacterSet . Utf8Mb4Binary && connectionCharacterSet == CharacterSet . Utf8Mb4Binary && resultsCharacterSet == CharacterSet . Utf8Mb4Binary ? CharacterSet . Utf8Mb4Binary :
150
+ clientCharacterSet == CharacterSet . Utf8Mb3Binary && connectionCharacterSet == CharacterSet . Utf8Mb3Binary && resultsCharacterSet == CharacterSet . Utf8Mb3Binary ? CharacterSet . Utf8Mb3Binary :
151
+ CharacterSet . None ;
152
+
153
+ if ( affectedRowCount == 0 && lastInsertId == 0 && warningCount == 0 && statusInfo is null && newSchema is null && clientCharacterSet is CharacterSet . None && connectionId is null )
133
154
{
134
155
if ( serverStatus == ServerStatus . AutoCommit )
135
156
return s_autoCommitOk ;
136
157
if ( serverStatus == ( ServerStatus . AutoCommit | ServerStatus . SessionStateChanged ) )
137
158
return s_autoCommitSessionStateChangedOk ;
138
159
}
139
160
140
- return new OkPayload ( affectedRowCount , lastInsertId , serverStatus , warningCount , statusInfo , newSchema , clientCharacterSet , connectionId ) ;
161
+ return new OkPayload ( affectedRowCount , lastInsertId , serverStatus , warningCount , statusInfo , newSchema , characterSet , connectionId ) ;
141
162
}
142
163
else
143
164
{
144
165
return null ;
145
166
}
146
167
}
147
168
148
- private OkPayload ( ulong affectedRowCount , ulong lastInsertId , ServerStatus serverStatus , int warningCount , string ? statusInfo , string ? newSchema , string ? clientCharacterSet , int ? connectionId )
169
+ private OkPayload ( ulong affectedRowCount , ulong lastInsertId , ServerStatus serverStatus , int warningCount , string ? statusInfo , string ? newSchema , CharacterSet newCharacterSet , int ? connectionId )
149
170
{
150
171
AffectedRowCount = affectedRowCount ;
151
172
LastInsertId = lastInsertId ;
152
173
ServerStatus = serverStatus ;
153
174
WarningCount = warningCount ;
154
175
StatusInfo = statusInfo ;
155
176
NewSchema = newSchema ;
156
- ClientCharacterSet = clientCharacterSet ;
157
- ConnectionId = connectionId ;
177
+ NewCharacterSet = newCharacterSet ;
178
+ NewConnectionId = connectionId ;
158
179
}
159
180
160
181
private static readonly OkPayload s_autoCommitOk = new ( 0 , 0 , ServerStatus . AutoCommit , 0 , default , default , default , default ) ;
0 commit comments