| ... | @@ -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: |
| 102 | pub fn createTable(self: Driver, alloc: std.mem.Allocator, comptime name: []const u8, comptime pk_name: []const u8, pk_type: type) !void { | 102 | pub 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 | } |
| 107 | | 107 | |
| 108 | pub fn addColumn(self: Driver, alloc: std.mem.Allocator, comptime table_name: []const u8, comptime col_name: []const u8, T: type) !void { | 108 | pub 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 { |
| 315 | | 315 | |
| 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 | } |
| 372 | | 373 | |
| | 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(); |