Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public virtual void Bind()
var value1 = (byte[])value;
BindBlob(value1);
}
else if (type == typeof(Memory<byte>))
{
var value1 = (Memory<byte>)value;
BindBlob(value1.Span);
}
else if (type == typeof(ReadOnlyMemory<byte>))
{
var value1 = (ReadOnlyMemory<byte>)value;
BindBlob(value1.Span);
}
else if (type == typeof(char))
{
var chr = (char)value;
Expand Down Expand Up @@ -240,6 +250,8 @@ public virtual void Bind()
{ typeof(bool), SqliteType.Integer },
{ typeof(byte), SqliteType.Integer },
{ typeof(byte[]), SqliteType.Blob },
{ typeof(Memory<byte>), SqliteType.Blob },
{ typeof(ReadOnlyMemory<byte>), SqliteType.Blob },
{ typeof(char), SqliteType.Text },
{ typeof(DateTime), SqliteType.Text },
{ typeof(DateTimeOffset), SqliteType.Text },
Expand Down
20 changes: 20 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ public void Bind_works_when_byte_array()
Bind_works(bytes, bytes);
}

[Fact]
public void Bind_works_when_read_only_memory_bytes()
{
var buffer = new byte[] { 0xBA, 0x7E, 0x57, 0xAB };
var input = ((ReadOnlyMemory<byte>)buffer).Slice(1, 2);
var expected = new byte[] { 0x7E, 0x57 };
Bind_works(input, expected);
}

[Fact]
public void Bind_works_when_memory_bytes()
{
var buffer = new byte[] { 0xBA, 0x7E, 0x57, 0xAB };
var input = ((Memory<byte>)buffer).Slice(1, 2);
var expected = new byte[] { 0x7E, 0x57 };
Bind_works(input, expected);
}

[Fact]
public void Bind_works_when_DateTime()
=> Bind_works(new DateTime(2014, 4, 14, 11, 13, 59), "2014-04-14 11:13:59");
Expand Down Expand Up @@ -598,6 +616,8 @@ public static IEnumerable<object[]> TypesData
new object[] { 0.0, SqliteType.Real },
new object[] { 0f, SqliteType.Real },
new object[] { Array.Empty<byte>(), SqliteType.Blob },
new object[] { new Memory<byte>([]), SqliteType.Blob },
new object[] { new ReadOnlyMemory<byte>([]), SqliteType.Blob },
};

private enum MyEnum
Expand Down