-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoids SET NAMES commands if not needed #1494
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using MySqlConnector.Protocol; | ||
|
||
namespace MySqlConnector.Core; | ||
|
||
internal sealed class Context | ||
{ | ||
public Context(ProtocolCapabilities protocolCapabilities, string? database, int connectionId) | ||
{ | ||
SupportsDeprecateEof = (protocolCapabilities & ProtocolCapabilities.DeprecateEof) != 0; | ||
SupportsCachedPreparedMetadata = (protocolCapabilities & ProtocolCapabilities.MariaDbCacheMetadata) != 0; | ||
SupportsQueryAttributes = (protocolCapabilities & ProtocolCapabilities.QueryAttributes) != 0; | ||
SupportsSessionTrack = (protocolCapabilities & ProtocolCapabilities.SessionTrack) != 0; | ||
ConnectionId = connectionId; | ||
Database = database; | ||
m_initialDatabase = database; | ||
} | ||
|
||
public bool SupportsDeprecateEof { get; } | ||
public bool SupportsQueryAttributes { get; } | ||
public bool SupportsSessionTrack { get; } | ||
public bool SupportsCachedPreparedMetadata { get; } | ||
public string? ClientCharset { get; set; } | ||
|
||
public string? Database { get; set; } | ||
private readonly string? m_initialDatabase; | ||
public bool IsInitialDatabase() => string.Equals(m_initialDatabase, Database, StringComparison.Ordinal); | ||
|
||
public int ConnectionId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior) | |
var firstByte = payload.HeaderByte; | ||
if (firstByte == OkPayload.Signature) | ||
{ | ||
var ok = OkPayload.Create(payload.Span, Session.SupportsDeprecateEof, Session.SupportsSessionTrack); | ||
var ok = OkPayload.Create(payload.Span, Session.Context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like bundling these together, but it could be done using a new interface that |
||
|
||
// if we've read a result set header then this is a SELECT statement, so we shouldn't overwrite RecordsAffected | ||
// (which should be -1 for SELECT) unless the server reports a non-zero count | ||
|
@@ -48,8 +48,6 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior) | |
if (ok.LastInsertId != 0) | ||
Command?.SetLastInsertedId((long) ok.LastInsertId); | ||
WarningCount = ok.WarningCount; | ||
if (ok.NewSchema is not null) | ||
Connection.Session.DatabaseOverride = ok.NewSchema; | ||
m_columnDefinitions = default; | ||
State = (ok.ServerStatus & ServerStatus.MoreResultsExist) == 0 | ||
? ResultSetState.NoMoreData | ||
|
@@ -109,7 +107,7 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior) | |
} | ||
else | ||
{ | ||
var columnCountPacket = ColumnCountPayload.Create(payload.Span, Session.SupportsCachedPreparedMetadata); | ||
var columnCountPacket = ColumnCountPayload.Create(payload.Span, Session.Context.SupportsCachedPreparedMetadata); | ||
var columnCount = columnCountPacket.ColumnCount; | ||
if (!columnCountPacket.MetadataFollows) | ||
{ | ||
|
@@ -132,7 +130,7 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior) | |
m_columnDefinitions = m_columnDefinitionPayloadCache.AsMemory(0, columnCount); | ||
|
||
// if the server supports metadata caching but has re-sent it, something has changed since last prepare/execution and we need to update the columns | ||
var preparedColumns = Session.SupportsCachedPreparedMetadata ? DataReader.LastUsedPreparedStatement?.Columns : null; | ||
var preparedColumns = Session.Context.SupportsCachedPreparedMetadata ? DataReader.LastUsedPreparedStatement?.Columns : null; | ||
|
||
for (var column = 0; column < columnCount; column++) | ||
{ | ||
|
@@ -156,7 +154,7 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior) | |
} | ||
} | ||
|
||
if (!Session.SupportsDeprecateEof) | ||
if (!Session.Context.SupportsDeprecateEof) | ||
{ | ||
payload = await Session.ReceiveReplyAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false); | ||
_ = EofPayload.Create(payload.Span); | ||
|
@@ -252,13 +250,13 @@ public async Task<bool> ReadAsync(IOBehavior ioBehavior, CancellationToken cance | |
|
||
if (payload.HeaderByte == EofPayload.Signature) | ||
{ | ||
if (Session.SupportsDeprecateEof && OkPayload.IsOk(payload.Span, Session.SupportsDeprecateEof)) | ||
if (Session.Context.SupportsDeprecateEof && OkPayload.IsOk(payload.Span, Session.Context)) | ||
{ | ||
var ok = OkPayload.Create(payload.Span, Session.SupportsDeprecateEof, Session.SupportsSessionTrack); | ||
var ok = OkPayload.Create(payload.Span, Session.Context); | ||
BufferState = (ok.ServerStatus & ServerStatus.MoreResultsExist) == 0 ? ResultSetState.NoMoreData : ResultSetState.HasMoreData; | ||
return null; | ||
} | ||
if (!Session.SupportsDeprecateEof && EofPayload.IsEof(payload)) | ||
if (!Session.Context.SupportsDeprecateEof && EofPayload.IsEof(payload)) | ||
{ | ||
var eof = EofPayload.Create(payload.Span); | ||
BufferState = (eof.ServerStatus & ServerStatus.MoreResultsExist) == 0 ? ResultSetState.NoMoreData : ResultSetState.HasMoreData; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the appeal in moving the connection-context-specific data into this new class, but I think it makes it harder to understand to have state spread across
ServerSession
and nowContext
. I'd rather this class be an immutable collection of data that's passed into methods that need to query the current capabilities.I also think it's a little "unpredictable" to have these properties updated without any notification that it's happening. (The old way wasn't great, either, in that code had to read the
OkPayload.NewSchema
and act on it, and if it didn't, that was a bug.) I also don't like the OkPayload parsing code having the side-effect of updating this mutable state, instead of just being a property-bag/DTO of all the data that was read out of the OK packet.Made it immutable here: 77ad191