Skip to content

Commit 25ed929

Browse files
committed
update m_characterSet and m_setNamesPayload initialization
1 parent 85dfcd8 commit 25ed929

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/SingleStoreConnector/Core/ServerSession.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,9 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
485485
SupportsQueryAttributes = (ServerCapabilities & ProtocolCapabilities.QueryAttributes) != 0;
486486
m_supportsSessionTrack = (ServerCapabilities & ProtocolCapabilities.SessionTrack) != 0;
487487
var serverSupportsSsl = (ServerCapabilities & ProtocolCapabilities.Ssl) != 0;
488-
m_characterSet = S2ServerVersion.Version >= S2Versions.SupportsUtf8Mb4 ? CharacterSet.Utf8Mb4GeneralCaseInsensitive : CharacterSet.Utf8GeneralCaseInsensitive;
489-
m_setNamesPayload = S2ServerVersion.Version >= S2Versions.SupportsUtf8Mb4 ?
490-
(SupportsQueryAttributes ? s_setNamesUtf8mb4WithAttributesPayload : s_setNamesUtf8mb4NoAttributesPayload) :
491-
(SupportsQueryAttributes ? s_setNamesUtf8WithAttributesPayload : s_setNamesUtf8NoAttributesPayload);
488+
// Default to plain UTF‑8 until we’ve probed the server’s real version
489+
m_characterSet = CharacterSet.Utf8GeneralCaseInsensitive;
490+
m_setNamesPayload = SupportsQueryAttributes ? s_setNamesUtf8WithAttributesPayload : s_setNamesUtf8NoAttributesPayload;
492491

493492
// disable pipelining for SingleStore
494493
m_supportsPipelining = false;
@@ -549,10 +548,25 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
549548
if (m_useCompression)
550549
m_payloadHandler = new CompressedPayloadHandler(m_payloadHandler.ByteHandler);
551550

552-
// set 'collation_connection' to the server default
553-
await SendAsync(m_setNamesPayload, ioBehavior, cancellationToken).ConfigureAwait(false);
554-
payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
555-
OkPayload.Verify(payload.Span, SupportsDeprecateEof, SupportsSessionTrack);
551+
// set 'collation_connection' to the server default (probing utf8mb4 support)
552+
try
553+
{
554+
var utf8Mb4Payload = SupportsQueryAttributes
555+
? s_setNamesUtf8mb4WithAttributesPayload
556+
: s_setNamesUtf8mb4NoAttributesPayload;
557+
await SendAsync(utf8Mb4Payload, ioBehavior, cancellationToken).ConfigureAwait(false);
558+
payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
559+
OkPayload.Verify(payload.Span, SupportsDeprecateEof, SupportsSessionTrack);
560+
561+
m_characterSet = CharacterSet.Utf8Mb4GeneralCaseInsensitive;
562+
m_setNamesPayload = utf8Mb4Payload;
563+
}
564+
catch (SingleStoreException)
565+
{
566+
await SendAsync(m_setNamesPayload, ioBehavior, cancellationToken).ConfigureAwait(false);
567+
var reply = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
568+
OkPayload.Verify(reply.Span, SupportsDeprecateEof, SupportsSessionTrack);
569+
}
556570

557571
await GetRealServerDetailsAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
558572

0 commit comments

Comments
 (0)