|
@@ -25,6 +25,8 @@ struct ConnectionData {
|
|
|
stmts: HashMap<u64, Statement>,
|
|
|
}
|
|
|
|
|
|
+unsafe impl Send for ConnectionData {}
|
|
|
+
|
|
|
pub(crate) trait PreparedKey {
|
|
|
fn into_u64(self) -> u64;
|
|
|
}
|
|
@@ -98,7 +100,7 @@ impl Connection {
|
|
|
if rcode != sq::SQLITE_OK {
|
|
|
let e = Error::Sqlite {
|
|
|
code: rcode,
|
|
|
- msg: if err == std::ptr::null_mut() {
|
|
|
+ msg: if err.is_null() {
|
|
|
CStr::from_ptr(sq::sqlite3_errstr(rcode))
|
|
|
} else {
|
|
|
CStr::from_ptr(err)
|
|
@@ -107,7 +109,7 @@ impl Connection {
|
|
|
.to_string(),
|
|
|
sql: Some(sql.as_ref().into()),
|
|
|
};
|
|
|
- if err != std::ptr::null_mut() {
|
|
|
+ if !err.is_null() {
|
|
|
sq::sqlite3_free(err.cast());
|
|
|
}
|
|
|
return Err(e);
|
|
@@ -146,7 +148,7 @@ impl Connection {
|
|
|
)?;
|
|
|
};
|
|
|
|
|
|
- if stmt == std::ptr::null_mut() {
|
|
|
+ if stmt.is_null() {
|
|
|
return Err(Error::InternalError(
|
|
|
"sqlite3_prepare_v2 returned a NULL stmt",
|
|
|
));
|
|
@@ -161,9 +163,8 @@ impl Connection {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-unsafe impl Send for Connection {}
|
|
|
-
|
|
|
struct Statement {
|
|
|
+ #[allow(unused)]
|
|
|
sqlite: *mut sq::sqlite3,
|
|
|
stmt: *mut sq::sqlite3_stmt,
|
|
|
}
|
|
@@ -299,19 +300,19 @@ pub trait Bindable {
|
|
|
fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()>;
|
|
|
}
|
|
|
|
|
|
-impl<'a> Bindable for () {
|
|
|
+impl Bindable for () {
|
|
|
fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()> {
|
|
|
unsafe { check_rcode(None, sq::sqlite3_bind_null(ctx.stmt.stmt, index)) }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<'a> Bindable for i64 {
|
|
|
+impl Bindable for i64 {
|
|
|
fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()> {
|
|
|
unsafe { check_rcode(None, sq::sqlite3_bind_int64(ctx.stmt.stmt, index, *self)) }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<'a> Bindable for usize {
|
|
|
+impl Bindable for usize {
|
|
|
fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()> {
|
|
|
(*self as i64).bind_to(ctx, index)
|
|
|
}
|
|
@@ -394,14 +395,14 @@ impl Readable for Vec<u8> {
|
|
|
let ptr = sq::sqlite3_column_blob(sr.stmt.stmt, index);
|
|
|
let len = sq::sqlite3_column_bytes(sr.stmt.stmt, index);
|
|
|
|
|
|
- if len == 0 {
|
|
|
- Ok(vec![])
|
|
|
- } else if len > 0 {
|
|
|
- Ok(std::slice::from_raw_parts(ptr.cast(), len as usize).to_vec())
|
|
|
- } else {
|
|
|
- Err(Error::InternalError(
|
|
|
+ match len.cmp(&0) {
|
|
|
+ std::cmp::Ordering::Equal => Ok(vec![]),
|
|
|
+ std::cmp::Ordering::Less => Err(Error::InternalError(
|
|
|
"negative length returned from sqlite3_column_bytes",
|
|
|
- ))
|
|
|
+ )),
|
|
|
+ std::cmp::Ordering::Greater => {
|
|
|
+ Ok(std::slice::from_raw_parts(ptr.cast(), len as usize).to_vec())
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|