aboutsummaryrefslogtreecommitdiff
path: root/zig-comments/src/pq.zig
diff options
context:
space:
mode:
Diffstat (limited to 'zig-comments/src/pq.zig')
-rw-r--r--zig-comments/src/pq.zig10
1 files changed, 6 insertions, 4 deletions
diff --git a/zig-comments/src/pq.zig b/zig-comments/src/pq.zig
index 52220fa..a4fc382 100644
--- a/zig-comments/src/pq.zig
+++ b/zig-comments/src/pq.zig
@@ -60,7 +60,7 @@ pub const Stmt = struct {
db: Db,
query: [:0]const u8,
aa: std.heap.ArenaAllocator,
-
+
n_params: usize = 0,
param_values: [MAX_PARAMS][*c]const u8 = undefined,
did_exec: bool = false,
@@ -71,7 +71,9 @@ pub const Stmt = struct {
pub fn deinit(self: *Stmt) void {
self.aa.deinit();
- pq.PQclear(self.c_res);
+ if (self.c_res != null) {
+ pq.PQclear(self.c_res);
+ }
}
pub fn step(self: *Stmt) !bool {
@@ -132,7 +134,7 @@ pub const Stmt = struct {
const ti = @typeInfo(T);
var t: T = undefined;
inline for (ti.Struct.fields) |field| {
- const name: [:0]const u8 = &addZ(field.name.len,field.name[0..].*);
+ const name: [:0]const u8 = &addZ(field.name.len, field.name[0..].*);
const val = try self.read_columnN(name, field.type);
@field(t, field.name) = val;
}
@@ -143,7 +145,7 @@ pub const Stmt = struct {
// https://github.com/ziglang/zig/issues/16116
pub fn addZ(comptime length: usize, value: [length]u8) [length:0]u8 {
var terminated_value: [length:0]u8 = undefined;
- terminated_value[length] = 0;
+ terminated_value[length] = 0;
@memcpy(&terminated_value, &value);
return terminated_value;
}