| ... | @@ -321,7 +321,7 @@ pub const Statement = struct { | ... | @@ -321,7 +321,7 @@ pub const Statement = struct { |
| 321 | return bindText(stmt, idx, value, SQLITE_STATIC); | 321 | return bindText(stmt, idx, value, SQLITE_STATIC); |
| 322 | } | 322 | } |
| 323 | if (comptime extras.isArrayOf(u8)(T)) { | 323 | if (comptime extras.isArrayOf(u8)(T)) { |
| 324 | return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, SQLITE_TRANSIENT)); | 324 | return bindBlob(stmt, idx, &value, SQLITE_TRANSIENT); |
| 325 | } | 325 | } |
| 326 | switch (@typeInfo(T)) { | 326 | switch (@typeInfo(T)) { |
| 327 | .@"struct" => |info| { | 327 | .@"struct" => |info| { |
| ... | @@ -384,6 +384,16 @@ pub const Statement = struct { | ... | @@ -384,6 +384,16 @@ pub const Statement = struct { |
| 384 | return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real, c.SQLITE_UTF8)); | 384 | return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real, c.SQLITE_UTF8)); |
| 385 | } | 385 | } |
| 386 | | 386 | |
| | 387 | fn bindBlob(stmt: Statement, idx: usize, value: []const u8, destructor: *allowzero anyopaque) !void { |
| | 388 | const destructor_real: c.sqlite3_destructor_type = blk: { |
| | 389 | // https://github.com/ziglang/translate-c/issues/128 |
| | 390 | @setRuntimeSafety(false); |
| | 391 | const ptr: c.sqlite3_destructor_type = @ptrCast(@alignCast(destructor)); |
| | 392 | break :blk ptr; |
| | 393 | }; |
| | 394 | return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real)); |
| | 395 | } |
| | 396 | |
| 387 | pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void { | 397 | pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void { |
| 388 | const iter = stmt.iterate(); | 398 | const iter = stmt.iterate(); |
| 389 | errdefer iter.reset(); | 399 | errdefer iter.reset(); |