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:...@@ -102,7 +102,7 @@ pub fn hasColumnWithName(self: Driver, alloc: std.mem.Allocator, comptime table:
102pub fn createTable(self: Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void {102pub fn createTable(self: Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void {
103 const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name });103 const t = tracer.trace(@src(), " {s} ({s})", .{ name, pk_name });
104 defer t.end();104 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) }), .{});
106}106}
107107
108pub fn addColumn(self: Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void {108pub 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 {...@@ -315,7 +315,7 @@ pub const Statement = struct {
315315
316 fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void {316 fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void {
317 if (comptime extras.isZigString(T)) {317 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);
319 }319 }
320 if (comptime extras.isArrayOf(u8)(T)) {320 if (comptime extras.isArrayOf(u8)(T)) {
321 return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, c.SQLITE_TRANSIENT));321 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 {...@@ -360,6 +360,7 @@ pub const Statement = struct {
360 switch (info.params.len) {360 switch (info.params.len) {
361 1 => {361 1 => {
362 const base = try value.bindField();362 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);
363 return bindType(stmt, allocator, idx, @TypeOf(base), base);364 return bindType(stmt, allocator, idx, @TypeOf(base), base);
364 },365 },
365 2 => {366 2 => {
...@@ -370,6 +371,10 @@ pub const Statement = struct {...@@ -370,6 +371,10 @@ pub const Statement = struct {
370 }371 }
371 }372 }
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
373 pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void {378 pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void {
374 const iter = stmt.iterate();379 const iter = stmt.iterate();
375 errdefer iter.reset();380 errdefer iter.reset();