diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs index 40cdbeb32c6..c9eabf0bc27 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs @@ -64,6 +64,16 @@ public virtual void Bind() var value1 = (byte[])value; BindBlob(value1); } + else if (type == typeof(Memory)) + { + var value1 = (Memory)value; + BindBlob(value1.Span); + } + else if (type == typeof(ReadOnlyMemory)) + { + var value1 = (ReadOnlyMemory)value; + BindBlob(value1.Span); + } else if (type == typeof(char)) { var chr = (char)value; @@ -240,6 +250,8 @@ public virtual void Bind() { typeof(bool), SqliteType.Integer }, { typeof(byte), SqliteType.Integer }, { typeof(byte[]), SqliteType.Blob }, + { typeof(Memory), SqliteType.Blob }, + { typeof(ReadOnlyMemory), SqliteType.Blob }, { typeof(char), SqliteType.Text }, { typeof(DateTime), SqliteType.Text }, { typeof(DateTimeOffset), SqliteType.Text }, diff --git a/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs b/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs index 97accd942af..cc5f4a314a6 100644 --- a/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs +++ b/test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs @@ -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)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)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"); @@ -598,6 +616,8 @@ public static IEnumerable TypesData new object[] { 0.0, SqliteType.Real }, new object[] { 0f, SqliteType.Real }, new object[] { Array.Empty(), SqliteType.Blob }, + new object[] { new Memory([]), SqliteType.Blob }, + new object[] { new ReadOnlyMemory([]), SqliteType.Blob }, }; private enum MyEnum