| ... | ... | @@ -5,6 +5,8 @@ const extras = @import("extras"); |
| 5 | 5 | const builtin = @import("builtin"); |
| 6 | 6 | |
| 7 | 7 | const Driver = @This(); |
| 8 | const SQLITE_STATIC: *allowzero anyopaque = @ptrFromInt(0); |
| 9 | const SQLITE_TRANSIENT: *allowzero anyopaque = @ptrFromInt(std.math.maxInt(usize)); |
| 8 | 10 | |
| 9 | 11 | db: *c.sqlite3, |
| 10 | 12 | |
| ... | ... | @@ -316,10 +318,10 @@ pub const Statement = struct { |
| 316 | 318 | |
| 317 | 319 | fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void { |
| 318 | 320 | if (comptime extras.isZigString(T)) { |
| 319 | | return bindText(stmt, idx, value, c.SQLITE_STATIC); |
| 321 | return bindText(stmt, idx, value, SQLITE_STATIC); |
| 320 | 322 | } |
| 321 | 323 | if (comptime extras.isArrayOf(u8)(T)) { |
| 322 | | return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, c.SQLITE_TRANSIENT)); |
| 324 | return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, SQLITE_TRANSIENT)); |
| 323 | 325 | } |
| 324 | 326 | switch (@typeInfo(T)) { |
| 325 | 327 | .@"struct" => |info| { |
| ... | ... | @@ -361,7 +363,7 @@ pub const Statement = struct { |
| 361 | 363 | switch (info.params.len) { |
| 362 | 364 | 1 => { |
| 363 | 365 | const base = try value.bindField(); |
| 364 | | if (T.BaseType == string and comptime extras.isArrayOf(u8)(@TypeOf(base))) return bindText(stmt, idx, &base, c.SQLITE_TRANSIENT); |
| 366 | if (T.BaseType == string and comptime extras.isArrayOf(u8)(@TypeOf(base))) return bindText(stmt, idx, &base, SQLITE_TRANSIENT); |
| 365 | 367 | return bindType(stmt, allocator, idx, @TypeOf(base), base); |
| 366 | 368 | }, |
| 367 | 369 | 2 => { |
| ... | ... | @@ -372,8 +374,14 @@ pub const Statement = struct { |
| 372 | 374 | } |
| 373 | 375 | } |
| 374 | 376 | |
| 375 | | fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: c.sqlite3_destructor_type) !void { |
| 376 | | return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor, c.SQLITE_UTF8)); |
| 377 | fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: *allowzero anyopaque) !void { |
| 378 | const destructor_real: c.sqlite3_destructor_type = blk: { |
| 379 | // https://github.com/ziglang/translate-c/issues/128 |
| 380 | @setRuntimeSafety(false); |
| 381 | const ptr: c.sqlite3_destructor_type = @ptrCast(@alignCast(destructor)); |
| 382 | break :blk ptr; |
| 383 | }; |
| 384 | return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real, c.SQLITE_UTF8)); |
| 377 | 385 | } |
| 378 | 386 | |
| 379 | 387 | pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void { |