aboutsummaryrefslogtreecommitdiff
path: root/zig-comments/src/pq.zig
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-08-14 21:45:25 +0100
committerMartin Ashby <martin@ashbysoft.com>2023-08-22 10:10:02 +0100
commit6a8a204020449fee3d8ef5e6175932e3731389f0 (patch)
tree35af7c5a1c19fa95c3c85d106cbc748fc20fc982 /zig-comments/src/pq.zig
parentff092976a9fdeeba96a0de13d013b9d838640c40 (diff)
downloadmfashby.net-6a8a204020449fee3d8ef5e6175932e3731389f0.tar.gz
mfashby.net-6a8a204020449fee3d8ef5e6175932e3731389f0.tar.bz2
mfashby.net-6a8a204020449fee3d8ef5e6175932e3731389f0.tar.xz
mfashby.net-6a8a204020449fee3d8ef5e6175932e3731389f0.zip
Misc fixes:
- fix template in comments.html: whitespace before tag names is not allowed - update mustache-zig version - null-terminate field names in zig struts, for C interop with PQfnumber function
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;
}