-
Notifications
You must be signed in to change notification settings - Fork 344
Implement COM_STMT_SEND_LONG_DATA #1579
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a82738f
Implement COM_STMT_SEND_LONG_DATA
ffe19aa
Merge master into send_long_data.
bgrainger 2b3765f
Overhaul implementation and add tests.
bgrainger c344032
Throw the exception.
bgrainger 140f572
Fix tests for MariaDB.
bgrainger 4cae698
Initialize ChunkStream with the data to read.
bgrainger c2c9f32
Exclude tests from MySql.Data.
bgrainger 8894090
Update documentation with Stream parameter support.
bgrainger 4638f17
Support multiple prepared statements in one command.
bgrainger 968cadf
Add test for multiple inserts in one prepared command.
bgrainger d74a1d7
WritePrologueAsync should be a no-op.
bgrainger cb2bb16
Fix exception when incorrect parameters are supplied.
bgrainger 9d726d2
Reuse a rented byte array.
bgrainger d05d248
Remove unused usings.
bgrainger e9811b5
Rename the method.
bgrainger 5db519d
Avoid unnecessary pass through the loop.
bgrainger 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,128 @@ | ||
namespace IntegrationTests; | ||
|
||
internal sealed class ChunkStream : Stream | ||
{ | ||
public ChunkStream(int dataLength, int chunkLength) | ||
{ | ||
m_dataLength = dataLength; | ||
m_chunkLength = chunkLength; | ||
m_position = 0; | ||
} | ||
|
||
public override bool CanRead => true; | ||
public override bool CanSeek => false; | ||
public override bool CanWrite => false; | ||
public override long Length => m_dataLength; | ||
public override long Position | ||
{ | ||
get => m_position; | ||
set => throw new NotSupportedException(); | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
if (buffer is null) | ||
throw new ArgumentNullException(nameof(buffer)); | ||
if (offset < 0 || offset > buffer.Length) | ||
throw new ArgumentOutOfRangeException(nameof(offset)); | ||
if (count < 0 || offset + count > buffer.Length) | ||
throw new ArgumentOutOfRangeException(nameof(count)); | ||
|
||
return Read(buffer.AsSpan(offset, count)); | ||
} | ||
|
||
public | ||
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER | ||
override | ||
#endif | ||
int Read(Span<byte> buffer) | ||
{ | ||
if (m_position >= m_dataLength) | ||
return 0; | ||
|
||
// Read at most chunkLength bytes | ||
var bytesToRead = Math.Min(buffer.Length, Math.Min(m_chunkLength, m_dataLength - m_position)); | ||
|
||
// Fill with dummy data (repeating pattern based on position) | ||
for (var i = 0; i < bytesToRead; i++) | ||
{ | ||
buffer[i] = (byte) ((m_position + i) % 256); | ||
} | ||
|
||
m_position += bytesToRead; | ||
return bytesToRead; | ||
} | ||
|
||
public override int ReadByte() | ||
{ | ||
Span<byte> buffer = stackalloc byte[1]; | ||
var bytesRead = Read(buffer); | ||
return bytesRead == 0 ? -1 : buffer[0]; | ||
} | ||
|
||
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | ||
{ | ||
if (buffer is null) | ||
throw new ArgumentNullException(nameof(buffer)); | ||
if (offset < 0 || offset > buffer.Length) | ||
throw new ArgumentOutOfRangeException(nameof(offset)); | ||
if (count < 0 || offset + count > buffer.Length) | ||
throw new ArgumentOutOfRangeException(nameof(count)); | ||
|
||
if (cancellationToken.IsCancellationRequested) | ||
return Task.FromCanceled<int>(cancellationToken); | ||
|
||
try | ||
{ | ||
return Task.FromResult(Read(buffer.AsSpan(offset, count))); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<int>(ex); | ||
} | ||
} | ||
|
||
public | ||
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER | ||
override | ||
#endif | ||
ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) | ||
{ | ||
if (cancellationToken.IsCancellationRequested) | ||
return new(Task.FromCanceled<int>(cancellationToken)); | ||
|
||
try | ||
{ | ||
return new(Read(buffer.Span)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new(Task.FromException<int>(ex)); | ||
} | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) => | ||
throw new NotSupportedException(); | ||
|
||
public override void WriteByte(byte value) => | ||
throw new NotSupportedException(); | ||
|
||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => | ||
throw new NotSupportedException(); | ||
|
||
public override void SetLength(long value) => | ||
throw new NotSupportedException(); | ||
|
||
public override long Seek(long offset, SeekOrigin origin) => | ||
throw new NotSupportedException(); | ||
|
||
public override void Flush() => | ||
throw new NotSupportedException(); | ||
|
||
public override Task FlushAsync(CancellationToken cancellationToken) => | ||
throw new NotSupportedException(); | ||
|
||
private readonly int m_dataLength; | ||
private readonly int m_chunkLength; | ||
private int m_position; | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.