diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs index fb737b44a12..b05d3ef8f66 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs @@ -10,16 +10,16 @@ namespace Microsoft.Data.Sqlite; internal class SqliteParameterBinder(sqlite3_stmt stmt, sqlite3 handle, int index, object value, int? size, SqliteType? sqliteType) : SqliteValueBinder(value, sqliteType) { - protected override void BindBlob(byte[] value) + protected override void BindBlob(ReadOnlySpan value) { var blob = value; if (ShouldTruncate(value.Length)) { - blob = new byte[size!.Value]; - Array.Copy(value, blob, size.Value); + blob = value.Slice(0, size!.Value); } var rc = sqlite3_bind_blob(stmt, index, blob); + SqliteException.ThrowExceptionForRC(rc, handle); } diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs index 48be075f3f7..9f4bbe19e20 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using SQLitePCL; using static SQLitePCL.raw; @@ -8,7 +9,7 @@ namespace Microsoft.Data.Sqlite; internal class SqliteResultBinder(sqlite3_context ctx, object? value) : SqliteValueBinder(value) { - protected override void BindBlob(byte[] value) + protected override void BindBlob(ReadOnlySpan value) => sqlite3_result_blob(ctx, value); protected override void BindDoubleCore(double value) diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs index 35fca9e4a44..40cdbeb32c6 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs @@ -35,7 +35,7 @@ protected virtual void BindDouble(double value) protected abstract void BindText(string value); - protected abstract void BindBlob(byte[] value); + protected abstract void BindBlob(ReadOnlySpan value); protected abstract void BindNull();