Skip to content
Open
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
16 changes: 12 additions & 4 deletions src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,12 @@ public virtual int Read(Span<byte> buffer)
count = (int)(Length - position);
}

var rc = sqlite3_blob_read(_blob, buffer.Slice(0, count), (int)position);
SqliteException.ThrowExceptionForRC(rc, _connection.Handle);
// Newer sqlite3_blob_read returns error for 0-byte reads.
if (count > 0)
{
var rc = sqlite3_blob_read(_blob, buffer.Slice(0, count), (int)position);
SqliteException.ThrowExceptionForRC(rc, _connection.Handle);
}
_position += count;
return count;
}
Expand Down Expand Up @@ -280,8 +284,12 @@ public virtual void Write(ReadOnlySpan<byte> buffer)
throw new NotSupportedException(Resources.ResizeNotSupported);
}

var rc = sqlite3_blob_write(_blob, buffer.Slice(0, count), (int)position);
SqliteException.ThrowExceptionForRC(rc, _connection.Handle);
// Newer sqlite3_blob_write returns error for 0-byte writes.
if (count > 0)
{
var rc = sqlite3_blob_write(_blob, buffer.Slice(0, count), (int)position);
SqliteException.ThrowExceptionForRC(rc, _connection.Handle);
}
_position += count;
}

Expand Down
Loading