Better error messages
This commit is contained in:
parent
e6217d543d
commit
cc44bbf12b
|
@ -28,8 +28,8 @@ pub const Sqlite = struct {
|
||||||
var stmt: ?*c.sqlite3_stmt = undefined;
|
var stmt: ?*c.sqlite3_stmt = undefined;
|
||||||
const err = c.sqlite3_prepare_v2(self.db, sql.ptr, @intCast(c_int, sql.len), &stmt, null);
|
const err = c.sqlite3_prepare_v2(self.db, sql.ptr, @intCast(c_int, sql.len), &stmt, null);
|
||||||
if (err != c.SQLITE_OK) {
|
if (err != c.SQLITE_OK) {
|
||||||
std.debug.print("sql error {}\n", .{err});
|
std.log.debug("sql error {}: {s}", .{ err, c.sqlite3_errmsg(self.db) });
|
||||||
std.debug.print("{s}\n", .{c.sqlite3_errmsg(self.db)});
|
std.log.debug("Failed on SQL:\n==========\n{s}\n==========", .{sql});
|
||||||
return error.UnknownError;
|
return error.UnknownError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ pub const PreparedStmt = struct {
|
||||||
c.SQLITE_DONE => null,
|
c.SQLITE_DONE => null,
|
||||||
|
|
||||||
else => |err| blk: {
|
else => |err| blk: {
|
||||||
std.debug.print("sql error {}\n", .{err});
|
std.log.debug("sql error {}: {s}", .{ err, c.sqlite3_errmsg(self.db) });
|
||||||
std.debug.print("{s}\n", .{c.sqlite3_errmsg(self.db)});
|
std.log.debug("Failed on SQL:\n==========\n{s}\n==========", .{self.getGeneratingSql()});
|
||||||
break :blk error.UnknownError;
|
break :blk error.UnknownError;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -150,4 +150,8 @@ pub const PreparedStmt = struct {
|
||||||
pub fn reset(self: *PreparedStmt) void {
|
pub fn reset(self: *PreparedStmt) void {
|
||||||
_ = c.sqlite3_reset(self.stmt);
|
_ = c.sqlite3_reset(self.stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn getGeneratingSql(self: *PreparedStmt) ?[*:0]const u8 {
|
||||||
|
return c.sqlite3_sql(self.stmt);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue