diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index cddf287..ba35b73 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -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 { - value.as_f64() + match value { + BorrowedValue::Integer(i) => Ok(i as f64), + BorrowedValue::Real(f) => Ok(f), + _ => Err(Error::InvalidColumnType), + } } } diff --git a/src/types/mod.rs b/src/types/mod.rs index d00693e..cfb8280 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -223,10 +223,9 @@ mod test { assert!(is_invalid_column_type(row.get_checked::>(1).err().unwrap())); // 2 is actually an integer - assert!(is_invalid_column_type(row.get_checked::(2).err().unwrap())); assert!(is_invalid_column_type(row.get_checked::(2).err().unwrap())); assert!(is_invalid_column_type(row.get_checked::>(2).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(2).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::>(2).err().unwrap())); // 3 is actually a float (c_double) assert!(is_invalid_column_type(row.get_checked::(3).err().unwrap()));