From 84bc9db37557d5887f1c31908d750c4e77a8c448 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 23 Sep 2021 22:12:24 -0700 Subject: add options parameter to bind/bindField --- sqlite.zig | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index 04a3b24..0bc3384 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -1100,7 +1100,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t /// } /// /// The types are checked at comptime. - fn bind(self: *Self, values: anytype) void { + fn bind(self: *Self, options: anytype, values: anytype) !void { const StructType = @TypeOf(values); const StructTypeInfo = @typeInfo(StructType).Struct; @@ -1129,7 +1129,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t const field_value = @field(values, struct_field.name); - self.bindField(struct_field.field_type, struct_field.name, _i, field_value); + try self.bindField(struct_field.field_type, options, struct_field.name, _i, field_value); } } @@ -1139,7 +1139,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t } } - fn bindField(self: *Self, comptime FieldType: type, comptime field_name: []const u8, i: c_int, field: FieldType) void { + fn bindField(self: *Self, comptime FieldType: type, options: anytype, comptime field_name: []const u8, i: c_int, field: FieldType) !void { const field_type_info = @typeInfo(FieldType); const column = i + 1; @@ -1152,7 +1152,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t .Float, .ComptimeFloat => _ = c.sqlite3_bind_double(self.stmt, column, field), .Bool => _ = c.sqlite3_bind_int64(self.stmt, column, @boolToInt(field)), .Pointer => |ptr| switch (ptr.size) { - .One => self.bindField(ptr.child, field_name, i, field.*), + .One => try self.bindField(ptr.child, options, field_name, i, field.*), .Slice => switch (ptr.child) { u8 => { _ = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(c_int, field.len), null); @@ -1172,17 +1172,17 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t } }, .Optional => |opt| if (field) |non_null_field| { - self.bindField(opt.child, field_name, i, non_null_field); + try self.bindField(opt.child, options, field_name, i, non_null_field); } else { _ = c.sqlite3_bind_null(self.stmt, column); }, .Null => _ = c.sqlite3_bind_null(self.stmt, column), .Enum => { if (comptime std.meta.trait.isZigString(FieldType.BaseType)) { - return self.bindField(FieldType.BaseType, field_name, i, @tagName(field)); + return try self.bindField(FieldType.BaseType, options, field_name, i, @tagName(field)); } if (@typeInfo(FieldType.BaseType) == .Int) { - return self.bindField(FieldType.BaseType, field_name, i, @enumToInt(field)); + return try self.bindField(FieldType.BaseType, options, field_name, i, @enumToInt(field)); } @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int to bind"); }, @@ -1199,7 +1199,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t /// in the input query string. /// pub fn exec(self: *Self, options: QueryOptions, values: anytype) !void { - self.bind(values); + try self.bind({}, values); var dummy_diags = Diagnostics{}; var diags = options.diags orelse &dummy_diags; @@ -1233,7 +1233,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t /// /// The iterator _must not_ outlive the statement. pub fn iterator(self: *Self, comptime Type: type, values: anytype) !Iterator(Type) { - self.bind(values); + try self.bind({}, values); var res: Iterator(Type) = undefined; res.db = self.db; -- cgit v1.2.3