From dabbb107d719cb753673e394fbd4da090f74d458 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Fri, 2 Aug 2024 13:23:21 +0200 Subject: WIP String queries and proper conversion: Still have to make the type checking better, not just an assert. Rethink. --- src/duckdb/Result.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/duckdb/Result.zig') 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){ -- cgit v1.2.3