Ryan Leckey 69ea41de1e sqlite: make the implementation far less naive
* WAL
 * sync = NORMAL, thought on this for awhile, all signs point to this being a very good default for WAL usage
 * separate worker thread per SQLite connection
2020-03-14 19:45:01 -07:00

36 lines
705 B
Rust

use crate::error::DatabaseError;
use libsqlite3_sys::sqlite3_errstr;
use std::ffi::CStr;
use std::os::raw::c_int;
pub struct SqliteError {
#[allow(dead_code)]
code: c_int,
message: String,
}
impl SqliteError {
pub(crate) fn new(code: c_int) -> Self {
#[allow(unsafe_code)]
let message = unsafe {
let err = sqlite3_errstr(code);
debug_assert!(!err.is_null());
CStr::from_ptr(err)
};
Self {
code,
message: message.to_string_lossy().into_owned(),
}
}
}
impl DatabaseError for SqliteError {
fn message(&self) -> &str {
&self.message
}
}
impl_fmt_error!(SqliteError);