summaryrefslogtreecommitdiff
path: root/src/duckdb/db.zig
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-01 22:33:27 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-01 22:45:22 +0200
commit3cf6abc4db67436200f60843fee8f81e052d0880 (patch)
tree8ffebdb191b316427ecbb47a2f661d323e572903 /src/duckdb/db.zig
parenta86a078a9707bdc3b0bd7ce9c8d72a89c8c942b4 (diff)
Simple querying passing!
Diffstat (limited to 'src/duckdb/db.zig')
-rw-r--r--src/duckdb/db.zig26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/duckdb/db.zig b/src/duckdb/db.zig
index 134a1f4..63826e4 100644
--- a/src/duckdb/db.zig
+++ b/src/duckdb/db.zig
@@ -55,22 +55,36 @@ test "Open and connect" {
defer connection.deinit();
}
-test "Query size" {
+test "Simple querying" {
var database = try Database.init(":memory:");
defer database.deinit();
var connection = try database.connect();
defer connection.deinit();
const s : type = comptime struct {
- primer: u8,
- segund: u8
+ primer: i32, // This is safe because the first column is NOT NULL
+ segund: ?i32
};
- _ = try connection.query("CREATE TABLE integers (i INTEGER, j INTEGER);", void);
- _ = try connection.query("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);", void);
+ var x = try connection.query("CREATE TABLE integers (i INTEGER NOT NULL, j INTEGER);", void);
+ x.deinit();
+ var y = try connection.query("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);", void);
+ y.deinit();
var result = try connection.query("SELECT * FROM integers;", s);
- _ = result.next();
defer result.deinit();
+
try std.testing.expect(2 == result.getColumnCount());
+
+ var z = try result.next();
+ try std.testing.expect(z.primer == 3);
+ try std.testing.expect(z.segund.? == 4);
+
+ z = try result.next();
+ try std.testing.expect(z.primer == 5);
+ try std.testing.expect(z.segund.? == 6);
+
+ z = try result.next();
+ try std.testing.expect(z.primer == 7);
+ try std.testing.expect(z.segund == null);
}