mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 08:59:29 +08:00
Allow FromSql::<f64> to work on SQLite integer values.
This commit is contained in:
parent
9d47d5109a
commit
4662b9b932
@ -1,5 +1,6 @@
|
||||
use super::{BorrowedValue, Value};
|
||||
use ::Result;
|
||||
use ::error::Error;
|
||||
|
||||
/// A trait for types that can be created from a SQLite value.
|
||||
pub trait FromSql: Sized {
|
||||
@ -20,7 +21,11 @@ impl FromSql for i64 {
|
||||
|
||||
impl FromSql for f64 {
|
||||
fn column_result(value: BorrowedValue) -> Result<Self> {
|
||||
value.as_f64()
|
||||
match value {
|
||||
BorrowedValue::Integer(i) => Ok(i as f64),
|
||||
BorrowedValue::Real(f) => Ok(f),
|
||||
_ => Err(Error::InvalidColumnType),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,10 +223,9 @@ mod test {
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<c_int>>(1).err().unwrap()));
|
||||
|
||||
// 2 is actually an integer
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_double>(2).err().unwrap()));
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, String>(2).err().unwrap()));
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, Vec<u8>>(2).err().unwrap()));
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<c_double>>(2).err().unwrap()));
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<String>>(2).err().unwrap()));
|
||||
|
||||
// 3 is actually a float (c_double)
|
||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_int>(3).err().unwrap()));
|
||||
|
Loading…
Reference in New Issue
Block a user