summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2021-04-27 21:05:10 +0200
committerGravatar Vincent Rischmann2021-04-27 21:31:25 +0200
commit90e9525b3873a1dad782a25d9cde3565520b9e2b (patch)
tree79205553b3ff2454e97a6931df860858e31f5272 /sqlite.zig
parentfix error name (diff)
downloadzig-sqlite-90e9525b3873a1dad782a25d9cde3565520b9e2b.tar.gz
zig-sqlite-90e9525b3873a1dad782a25d9cde3565520b9e2b.tar.xz
zig-sqlite-90e9525b3873a1dad782a25d9cde3565520b9e2b.zip
workaround compiler bug
This workaround allows one to write this: const Foobar = struct { foo: usize, bar: []const u8, }; const row = try stmt.one(Foobar); Where the first field in the struct (here `foo`) is either an integer type, a float type or a boolean. Moving the first field of this type to second position resolves the bug. This is because readInt, readFloat and readBool have an empty error set and cause this bug to trigger. Removing the error altogether also triggers the bug so we define an explicit error set. If we actually want to return an error from these functions we'll simply remove the workaround. See https://github.com/ziglang/zig/issues/5149
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig12
1 files changed, 9 insertions, 3 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 097c7a9..cad4a6e 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -667,19 +667,25 @@ pub fn Iterator(comptime Type: type) type {
667 } 667 }
668 668
669 // readInt reads a sqlite INTEGER column into an integer. 669 // readInt reads a sqlite INTEGER column into an integer.
670 fn readInt(self: *Self, comptime IntType: type, i: usize) !IntType { 670 //
671 // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error
672 fn readInt(self: *Self, comptime IntType: type, i: usize) error{Workaround}!IntType {
671 const n = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); 673 const n = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i));
672 return @intCast(IntType, n); 674 return @intCast(IntType, n);
673 } 675 }
674 676
675 // readFloat reads a sqlite REAL column into a float. 677 // readFloat reads a sqlite REAL column into a float.
676 fn readFloat(self: *Self, comptime FloatType: type, i: usize) !FloatType { 678 //
679 // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error
680 fn readFloat(self: *Self, comptime FloatType: type, i: usize) error{Workaround}!FloatType {
677 const d = c.sqlite3_column_double(self.stmt, @intCast(c_int, i)); 681 const d = c.sqlite3_column_double(self.stmt, @intCast(c_int, i));
678 return @floatCast(FloatType, d); 682 return @floatCast(FloatType, d);
679 } 683 }
680 684
681 // readFloat reads a sqlite INTEGER column into a bool (true is anything > 0, false is anything <= 0). 685 // readFloat reads a sqlite INTEGER column into a bool (true is anything > 0, false is anything <= 0).
682 fn readBool(self: *Self, i: usize) !bool { 686 //
687 // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error
688 fn readBool(self: *Self, i: usize) error{Workaround}!bool {
683 const d = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); 689 const d = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i));
684 return d > 0; 690 return d > 0;
685 } 691 }