summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Luna2022-03-31 01:10:31 -0300
committerGravatar Vincent Rischmann2022-04-24 11:22:42 +0200
commite151e8c3e8f5e444182419c464b385c0c165497c (patch)
treefc467f678494076447a3e74516c34b67916a6698
parentupdate sqlite bundled source code to 3.38.2 (diff)
downloadzig-sqlite-e151e8c3e8f5e444182419c464b385c0c165497c.tar.gz
zig-sqlite-e151e8c3e8f5e444182419c464b385c0c165497c.tar.xz
zig-sqlite-e151e8c3e8f5e444182419c464b385c0c165497c.zip
allow slices to be passed as bind parameters
Diffstat (limited to '')
-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