summaryrefslogtreecommitdiff
path: root/src/duckdb/Database.zig
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-05 22:20:19 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-05 22:20:46 +0200
commit8efa7cb0013aae1708e2d815b7fa65f055062159 (patch)
tree4b815a71d8d09b00a29d9435f5b52369fa482081 /src/duckdb/Database.zig
parent2c5149d5ca84b28d371dffa2c5ea3cae53c93a8e (diff)
Results with proper conversion
Diffstat (limited to 'src/duckdb/Database.zig')
-rw-r--r--src/duckdb/Database.zig34
1 files changed, 33 insertions, 1 deletions
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();