diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/duckdb/Result.zig | 8 | ||||
-rw-r--r-- | src/duckdb/db.zig | 9 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/duckdb/Result.zig b/src/duckdb/Result.zig index 75f74fd..61a30ce 100644 --- a/src/duckdb/Result.zig +++ b/src/duckdb/Result.zig @@ -23,19 +23,15 @@ pub fn Result(comptime T: type) type{ const Self = @This(); - pub fn init(conn : c.duckdb_connection, query: [:0]const u8) !Self { + pub fn init(result: c.duckdb_result) !Self { var self : Self = .{ - ._res = undefined, + ._res = result, ._chunk = null, ._columns = undefined, ._validities = undefined, ._data = undefined, ._current_row = 0, }; - const state = c.duckdb_query(conn, query, &self._res); - if ( state == c.DuckDBError){ - return error.DuckDBError; - } self.fetchDataChunk(); if( column_count != 0 and column_count != self.getColumnCount() ){ diff --git a/src/duckdb/db.zig b/src/duckdb/db.zig index 41cfe67..4b5ebe3 100644 --- a/src/duckdb/db.zig +++ b/src/duckdb/db.zig @@ -24,12 +24,17 @@ const Connection = struct { /// Query returning a result. Caller needs to call result.deinit() pub fn query(self: *Connection, q: [:0]const u8, comptime res_type: type) !Result(res_type) { - return try Result(res_type).init(self._conn, q); + var result: c.duckdb_result = undefined; + const state = c.duckdb_query(self._conn, q, &result); + if ( state == c.DuckDBError ){ + return error.DuckDBError; + } + return try Result(res_type).init(result); } /// Query with no results and autoclean pub fn run(self: *Connection, q: [:0]const u8) !void{ - var x = try Result(void).init(self._conn, q); + var x = try self.query(q, void); defer x.deinit(); } }; |