Skip to content

Support Memory and ReadOnlyMemory parameter binding in Microsoft.Data.Sqlite #37484

@joelverhagen

Description

@joelverhagen

What problem are you trying to solve?

Currently, you can only reduce memory usage of SQLIT byte binding by using a byte[] (perhaps from an array pool) and setting the SqliteParameter.Size property to the actual size of the data. With #37436 this produces no additional byte array allocations on the heap by passing a ReadOnlySpan<byte> to the underlying library bindings.

But what if the desired blob to bind is not at the beginning of the array, for example you want to slice a byte array into multiple columns?

This should be possible with Memory<byte> or ReadOnlyMemory<byte> structs. But only byte[] is supported for binding.

The SqliteParameterBinder can easily be enhanced to support these two structs.

These will of course round trip as a byte[] so the ownership of the bytes is given to the code querying the DB, but in this write (INSERT/UPDATE) path supporting slices semantics is beneficial to allow reduced allocations.

Describe the solution you'd like

Support binding Memory<byte> and ReadOnlyMemory<byte>.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions