diff --git a/Changelog.md b/Changelog.md index 5df3a74..4a44370 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# Version 0.10.2 (UPCOMING) + +* Adds `FromSql` and `ToSql` impls for `isize`. Documents why `usize` and `u64` are not included. + # Version 0.10.1 (2017-03-03) * Updates the `bundled` SQLite version to 3.17.0. diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index 415ff27..ab79750 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -49,6 +49,14 @@ impl Error for FromSqlError { pub type FromSqlResult = Result; /// A trait for types that can be created from a SQLite value. +/// +/// Note that `FromSql` and `ToSql` are defined for most integral types, but not `u64` or `usize`. +/// This is intentional; SQLite returns integers as signed 64-bit values, which cannot fully +/// represent the range of these types. Rusqlite would have to decide how to handle negative +/// values: return an error or reinterpret as a very large postive numbers, neither of which is +/// guaranteed to be correct for everyone. Callers can work around this by fetching values as i64 +/// and then doing the interpretation themselves or by defining a newtype and implementing +/// `FromSql`/`ToSql` for it. pub trait FromSql: Sized { fn column_result(value: ValueRef) -> FromSqlResult; } @@ -72,6 +80,7 @@ macro_rules! from_sql_integral( from_sql_integral!(i8); from_sql_integral!(i16); from_sql_integral!(i32); +from_sql_integral!(isize); from_sql_integral!(u8); from_sql_integral!(u16); from_sql_integral!(u32); diff --git a/src/types/to_sql.rs b/src/types/to_sql.rs index 0e4d754..3d4df7f 100644 --- a/src/types/to_sql.rs +++ b/src/types/to_sql.rs @@ -74,6 +74,7 @@ to_sql_self!(i8); to_sql_self!(i16); to_sql_self!(i32); to_sql_self!(i64); +to_sql_self!(isize); to_sql_self!(u8); to_sql_self!(u16); to_sql_self!(u32); diff --git a/src/types/value.rs b/src/types/value.rs index e192826..65dfc94 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -43,6 +43,7 @@ macro_rules! from_i64( from_i64!(i8); from_i64!(i16); from_i64!(i32); +from_i64!(isize); from_i64!(u8); from_i64!(u16); from_i64!(u32);