diff --git a/src/sqlite3.zig b/src/sqlite3.zig index b344553c7e7bdfdc824ced4777082ab64c1b222f..5bdcdc50855bbd4f7ab6aaae8eedc4cd33c73485 100644 --- a/src/sqlite3.zig +++ b/src/sqlite3.zig @@ -321,7 +321,7 @@ pub const Statement = struct { return bindText(stmt, idx, value, SQLITE_STATIC); } if (comptime extras.isArrayOf(u8)(T)) { - return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, SQLITE_TRANSIENT)); + return bindBlob(stmt, idx, &value, SQLITE_TRANSIENT); } switch (@typeInfo(T)) { .@"struct" => |info| { @@ -384,6 +384,16 @@ pub const Statement = struct { return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real, c.SQLITE_UTF8)); } + fn bindBlob(stmt: Statement, idx: usize, value: []const u8, destructor: *allowzero anyopaque) !void { + const destructor_real: c.sqlite3_destructor_type = blk: { + // https://github.com/ziglang/translate-c/issues/128 + @setRuntimeSafety(false); + const ptr: c.sqlite3_destructor_type = @ptrCast(@alignCast(destructor)); + break :blk ptr; + }; + return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real)); + } + pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void { const iter = stmt.iterate(); errdefer iter.reset();