Open lun-4 opened 1 year ago
While exploring #118, I noticed that passing the entire struct as a parameter to the query turns it into stack memory by the time custom bindField
is run, which breaks the assumption I had that bindField would have a custom struct with the lifetime of the entire statement, instead it has the lifetime of the bindField()
internal function, so the const pointer that I take in the custom one is completely invalid by the time the query is executed. Ooops.
Not sure how to approach this one other than going back to ID.sql()
as with that I know that I am using the ID
with the correct lifetime. Suggestions welcome.
My custom struct is a wrapper around a
[26]u8
While exploring things, I noticed that
bindField()
override exists, and that I could use it to remove the need to writeid.sql()
in my queries, however, that method interface would not suffice for my usecase:https://github.com/vrischmann/zig-sqlite/blob/b98ebdf4a9f038ca6322e6091e45c4998efad946/sqlite.zig#L1661
If I wanted to remove
id.sql()
calls, I would then need to add unnecessary allocators to every SQL call that gives an ID struct as an argument, even though the memory that I want to pass to SQLite is already available on the stack by the time I want to execute the query. ExampleMaybe we could check argument count at comptime and not require allocators if argument count is 1?