authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-18 00:50:58-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-18 00:50:58-07:00
log6d8caab9c190efeb6bb7b9b7ff03193938adb433
tree610fb2f3fcfbeb2090b76174ed73f14612906953
parent6bfea5381bb321455adc2077d76a154cff9a1f01
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

sqlite3: fixes to enable strict tables


1 files changed, 7 insertions(+), 2 deletions(-)

src/sqlite3.zig+7-2
......@@ -102,7 +102,7 @@ pub fn hasColumnWithName(self: Driver, alloc: std.mem.Allocator, comptime table:
102102pub fn createTable(self: Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void {
103103 const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name });
104104 defer t.end();
105 try self.exec(alloc, comptime std.fmt.comptimePrint("create table {s}({s} {s} primary key not null)", .{ name, pk_name, nameForType2(pk_type) }), .{});
105 try self.exec(alloc, comptime std.fmt.comptimePrint("create table {s}({s} {s} primary key not null) strict", .{ name, pk_name, nameForType2(pk_type) }), .{});
106106}
107107
108108pub fn addColumn(self: Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void {
......@@ -315,7 +315,7 @@ pub const Statement = struct {
315315
316316 fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void {
317317 if (comptime extras.isZigString(T)) {
318 return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, c.SQLITE_STATIC, c.SQLITE_UTF8));
318 return bindText(stmt, idx, value, c.SQLITE_STATIC);
319319 }
320320 if (comptime extras.isArrayOf(u8)(T)) {
321321 return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, c.SQLITE_TRANSIENT));
......@@ -360,6 +360,7 @@ pub const Statement = struct {
360360 switch (info.params.len) {
361361 1 => {
362362 const base = try value.bindField();
363 if (T.BaseType == string and comptime extras.isArrayOf(u8)(@TypeOf(base))) return bindText(stmt, idx, &base, c.SQLITE_TRANSIENT);
363364 return bindType(stmt, allocator, idx, @TypeOf(base), base);
364365 },
365366 2 => {
......@@ -370,6 +371,10 @@ pub const Statement = struct {
370371 }
371372 }
372373
374 fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: c.sqlite3_destructor_type) !void {
375 return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor, c.SQLITE_UTF8));
376 }
377
373378 pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void {
374379 const iter = stmt.iterate();
375380 errdefer iter.reset();