summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig13
1 files changed, 11 insertions, 2 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 62950c8..6174d1c 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -1490,8 +1490,12 @@ pub fn Iterator(comptime Type: type) type {
1490 } 1490 }
1491 @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int"); 1491 @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int");
1492 }, 1492 },
1493 .@"struct" => |TI| { 1493 inline .@"struct", .@"union" => |TI| {
1494 if (TI.layout == .@"packed") return @bitCast(try self.readInt(TI.backing_integer.?, i)); 1494 if (TI.layout == .@"packed" and !@hasField(FieldType, "readField")) {
1495 const Backing = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(FieldType) } });
1496 return @bitCast(try self.readInt(Backing, i));
1497 }
1498
1495 const inner_value = try self.readField(FieldType.BaseType, options, i); 1499 const inner_value = try self.readField(FieldType.BaseType, options, i);
1496 return try FieldType.readField(options.allocator, inner_value); 1500 return try FieldType.readField(options.allocator, inner_value);
1497 }, 1501 },
@@ -1714,6 +1718,11 @@ pub const DynamicStatement = struct {
1714 try self.bindField(FieldType.BaseType, options, field_name, i, field_value); 1718 try self.bindField(FieldType.BaseType, options, field_name, i, field_value);
1715 }, 1719 },
1716 .@"union" => |info| { 1720 .@"union" => |info| {
1721 if (info.layout == .@"packed") {
1722 const Backing = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(FieldType) } });
1723 try self.bindField(Backing, options, field_name, i, @as(Backing, @bitCast(field)));
1724 return;
1725 }
1717 if (info.tag_type) |UnionTagType| { 1726 if (info.tag_type) |UnionTagType| {
1718 inline for (info.fields) |u_field| { 1727 inline for (info.fields) |u_field| {
1719 // This wasn't entirely obvious when I saw code like this elsewhere, it works because of type coercion. 1728 // This wasn't entirely obvious when I saw code like this elsewhere, it works because of type coercion.