diff options
Diffstat (limited to 'src/duckdb/Result.zig')
-rw-r--r-- | src/duckdb/Result.zig | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/duckdb/Result.zig b/src/duckdb/Result.zig index f399fb5..75f74fd 100644 --- a/src/duckdb/Result.zig +++ b/src/duckdb/Result.zig @@ -1,4 +1,5 @@ -const std = @import("std"); +const std = @import("std"); +const types = @import("Types.zig"); const c = @cImport({ @cInclude("duckdb.h"); }); @@ -102,7 +103,7 @@ pub fn Result(comptime T: type) type{ // TODO: check compatibility between the column type and // the struct provided as result container // - // const column_type = c.duckdb_column_type(&self._res, i); + const column_type = c.duckdb_column_type(&self._res, i); // std.debug.print("tipo => {any}\n", .{column_type}); // std.debug.print("{any}\n", .{self._data}); @@ -123,8 +124,12 @@ pub fn Result(comptime T: type) type{ .Optional => |t| t.child, else => field.type }; - const col : [*]t = @alignCast(@ptrCast(self._data[i])); - @field(result, field.name) = col[self._current_row]; + // Unpack the C array of duckdb_type + const col: [*]types.unpack_type(t) = @alignCast(@ptrCast(self._data[i])); + std.debug.assert(types.valid_unpack(column_type, t)); + + // Convert to Zig data type + @field(result, field.name) = try types.cast(&col[self._current_row], t); } else { // Got a NULL from the DB if (@typeInfo(field.type) != .Optional){ |