diff --git a/src/sql/lib.zig b/src/sql/lib.zig index 919ce21..ba62de4 100644 --- a/src/sql/lib.zig +++ b/src/sql/lib.zig @@ -28,8 +28,8 @@ pub const Sqlite = struct { var stmt: ?*c.sqlite3_stmt = undefined; const err = c.sqlite3_prepare_v2(self.db, sql.ptr, @intCast(c_int, sql.len), &stmt, null); if (err != c.SQLITE_OK) { - std.debug.print("sql error {}\n", .{err}); - std.debug.print("{s}\n", .{c.sqlite3_errmsg(self.db)}); + std.log.debug("sql error {}: {s}", .{ err, c.sqlite3_errmsg(self.db) }); + std.log.debug("Failed on SQL:\n==========\n{s}\n==========", .{sql}); return error.UnknownError; } @@ -136,8 +136,8 @@ pub const PreparedStmt = struct { c.SQLITE_DONE => null, else => |err| blk: { - std.debug.print("sql error {}\n", .{err}); - std.debug.print("{s}\n", .{c.sqlite3_errmsg(self.db)}); + std.log.debug("sql error {}: {s}", .{ err, c.sqlite3_errmsg(self.db) }); + std.log.debug("Failed on SQL:\n==========\n{s}\n==========", .{self.getGeneratingSql()}); break :blk error.UnknownError; }, }; @@ -150,4 +150,8 @@ pub const PreparedStmt = struct { pub fn reset(self: *PreparedStmt) void { _ = c.sqlite3_reset(self.stmt); } + + fn getGeneratingSql(self: *PreparedStmt) ?[*:0]const u8 { + return c.sqlite3_sql(self.stmt); + } };