summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sqlite.zig31
1 files changed, 22 insertions, 9 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 3688648..f1add39 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -1727,17 +1727,30 @@ pub const DynamicStatement = struct {
1727 // If however there are no name bind markers then the behaviour will revert to using the field index in the struct, and the fields order must be correct. 1727 // If however there are no name bind markers then the behaviour will revert to using the field index in the struct, and the fields order must be correct.
1728 fn bind(self: *Self, options: anytype, values: anytype) !void { 1728 fn bind(self: *Self, options: anytype, values: anytype) !void {
1729 const StructType = @TypeOf(values); 1729 const StructType = @TypeOf(values);
1730 const StructTypeInfo = @typeInfo(StructType).Struct;
1731 1730
1732 inline for (StructTypeInfo.fields) |struct_field, struct_field_i| { 1731 switch (@typeInfo(StructType)) {
1733 const field_value = @field(values, struct_field.name); 1732 .Struct => |StructTypeInfo| {
1733 inline for (StructTypeInfo.fields) |struct_field, struct_field_i| {
1734 const field_value = @field(values, struct_field.name);
1734 1735
1735 const i = sqlite3BindParameterIndex(self.stmt, struct_field.name); 1736 const i = sqlite3BindParameterIndex(self.stmt, struct_field.name);
1736 if (i >= 0) { 1737 if (i >= 0) {
1737 try self.bindField(struct_field.field_type, options, struct_field.name, i, field_value); 1738 try self.bindField(struct_field.field_type, options, struct_field.name, i, field_value);
1738 } else { 1739 } else {
1739 try self.bindField(struct_field.field_type, options, struct_field.name, struct_field_i, field_value); 1740 try self.bindField(struct_field.field_type, options, struct_field.name, struct_field_i, field_value);
1740 } 1741 }
1742 }
1743 },
1744 .Pointer => |PointerTypeInfo| {
1745 // TODO support other pointer types
1746 std.debug.assert(PointerTypeInfo.size == .Slice);
1747
1748 for (values) |value_to_bind, index| {
1749 std.log.info("awooga {} {}", .{ value_to_bind, index });
1750 try self.bindField(PointerTypeInfo.child, options, "", @intCast(c_int, index), value_to_bind);
1751 }
1752 },
1753 else => @compileError("Unsupported type for values: " ++ @typeName(StructType)),
1741 } 1754 }
1742 } 1755 }
1743 1756