Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
Quick and dirty fix for S2
Browse files Browse the repository at this point in the history
Those changes are workaround for issues when using this client on
SingleStore.
It is not meant to be production grade changes yet, but allows us to
continue testing our solution against S2.
  • Loading branch information
sfoutrier committed Dec 2, 2021
1 parent dbadd12 commit b548db4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/MySqlConnector/Core/ServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void FinishQuerying()
// In order to handle this case, we issue a dummy query that will consume the pending cancellation.
// See https://bugs.mysql.com/bug.php?id=45679
Log.Debug("Session{0} sending 'DO SLEEP(0)' command to clear pending cancellation", m_logArguments);
var payload = QueryPayload.Create(SupportsQueryAttributes, "DO SLEEP(0);");
var payload = QueryPayload.Create(SupportsQueryAttributes, "SELECT SLEEP(0) INTO @dummy;");
#pragma warning disable CA2012 // Safe because method completes synchronously
SendAsync(payload, IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
payload = ReceiveReplyAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
Expand Down Expand Up @@ -1200,7 +1200,7 @@ private async Task<bool> OpenNamedPipeAsync(ConnectionSettings cs, int startTick
await namedPipeStream.ConnectAsync(timeout, cancellationToken).ConfigureAwait(false);
else
#endif
namedPipeStream.Connect(timeout);
namedPipeStream.Connect(timeout);
}
catch (Exception ex) when ((ex is ObjectDisposedException && cancellationToken.IsCancellationRequested) || ex is TimeoutException)
{
Expand Down
28 changes: 22 additions & 6 deletions src/MySqlConnector/MySqlParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
var length = inputSpan.Length + BinaryBytes.Length + 1;
foreach (var by in inputSpan)
{
if (by is 0x27 || by is 0x5C && !noBackslashEscapes)
if (by is 0x27 || by is 0x5C && !noBackslashEscapes || by is 0x00)
length++;
}

Expand All @@ -297,9 +297,17 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
var index = BinaryBytes.Length;
foreach (var by in inputSpan)
{
if (by is 0x27 || by is 0x5C && !noBackslashEscapes)
if (by is 0x00)
{
outputSpan[index++] = (byte) '\\';
outputSpan[index++] = (byte) '0';
}
else
{
if (by is 0x27 || by is 0x5C && !noBackslashEscapes)
outputSpan[index++] = by;
outputSpan[index++] = by;
outputSpan[index++] = by;
}
}
outputSpan[index++] = 0x27;
Debug.Assert(index == length, "index == length");
Expand Down Expand Up @@ -394,9 +402,17 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
writer.Write(BinaryBytes);
foreach (var by in bytes)
{
if (by is 0x27 or 0x5C)
writer.Write((byte) 0x5C);
writer.Write(by);
if (by is 0x00)
{
writer.Write((byte) '\\');
writer.Write((byte) '0');
}
else
{
if (by is 0x27 or 0x5C)
writer.Write((byte) 0x5C);
writer.Write(by);
}
}
writer.Write((byte) '\'');
}
Expand Down

2 comments on commit b548db4

@bgrainger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, some of these syntax changes may need to be upstreamed for mysql-net#1115.

@bgrainger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I also opened mysql-net#1121 to improve compatibility upstream.

Please sign in to comment.