From 8efa7cb0013aae1708e2d815b7fa65f055062159 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 5 Aug 2024 22:20:19 +0200 Subject: Results with proper conversion --- src/duckdb/Database.zig | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/duckdb/Database.zig') diff --git a/src/duckdb/Database.zig b/src/duckdb/Database.zig index ca2a03a..ffdd052 100644 --- a/src/duckdb/Database.zig +++ b/src/duckdb/Database.zig @@ -72,7 +72,39 @@ test "Simple querying" { try std.testing.expect(z.segund == null); } -test "Checks if all fields are captured" { +test "Simple querying with conversion" { + var database = try Self.init(":memory:"); + defer database.deinit(); + var connection = try database.connect(); + defer connection.deinit(); + + const s : type = comptime struct { + primer: f64, // Converting to f64 + segund: ?i32 + }; + + try connection.run("CREATE TABLE integers (i INTEGER NOT NULL, j INTEGER);"); + try connection.run("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);"); + var result = try connection.query("SELECT * FROM integers;", s); + defer result.deinit(); + + + try std.testing.expect(2 == result.getColumnCount()); + + var z = try result.next(); + try std.testing.expect(z.primer == 3.0); + try std.testing.expect(z.segund.? == 4); + + z = try result.next(); + try std.testing.expect(z.primer == 5.0); + try std.testing.expect(z.segund.? == 6); + + z = try result.next(); + try std.testing.expect(z.primer == 7.0); + try std.testing.expect(z.segund == null); +} + +test "All fields are captured" { var database = try Self.init(":memory:"); defer database.deinit(); var connection = try database.connect(); -- cgit v1.2.3