Better error messages

This commit is contained in:
jaina heartles 2022-07-21 21:18:20 -07:00
parent e6217d543d
commit cc44bbf12b
1 changed files with 8 additions and 4 deletions

View File

@ -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);
}
};