summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-08-01 23:28:54 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-08-01 23:28:54 +0200
commit7a1f944779d858a6e1b80cf391e03fbbbecb4a43 (patch)
tree6a16385541459f9a5de208ab5f690f30fc0c55f9
parent3cf6abc4db67436200f60843fee8f81e052d0880 (diff)
Check all the fields are captured
-rw-r--r--src/duckdb/Result.zig6
-rw-r--r--src/duckdb/db.zig21
2 files changed, 26 insertions, 1 deletions
diff --git a/src/duckdb/Result.zig b/src/duckdb/Result.zig
index 53ed351..8e06b67 100644
--- a/src/duckdb/Result.zig
+++ b/src/duckdb/Result.zig
@@ -35,8 +35,12 @@ pub fn Result(comptime T: type) type{
if ( state == c.DuckDBError){
return error.DuckDBError;
}
-
self.fetchDataChunk();
+ if( column_count != 0 and
+ column_count != self.getColumnCount() ){
+ return error.QueryColumnCountCapture;
+ }
+
return self;
}
pub fn deinit(self: *Self) void {
diff --git a/src/duckdb/db.zig b/src/duckdb/db.zig
index 63826e4..19feffe 100644
--- a/src/duckdb/db.zig
+++ b/src/duckdb/db.zig
@@ -88,3 +88,24 @@ test "Simple querying" {
try std.testing.expect(z.primer == 7);
try std.testing.expect(z.segund == null);
}
+
+test "Checks if all fields are captured" {
+ var database = try Database.init(":memory:");
+ defer database.deinit();
+ var connection = try database.connect();
+ defer connection.deinit();
+
+ const s : type = comptime struct {
+ primer: ?i32,
+ segund: ?i32,
+ tercer: ?i32,
+ };
+
+ 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();
+
+ try std.testing.expectError(error.QueryColumnCountCapture,
+ connection.query("SELECT * FROM integers;", s));
+}