summaryrefslogtreecommitdiff
path: root/src/duckdb/Database.zig
diff options
context:
space:
mode:
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();