diff --git a/Cargo.toml b/Cargo.toml index f66daac..e7825f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rusqlite" -version = "0.9.2" +version = "0.9.3" authors = ["John Gallagher "] description = "Ergonomic wrapper for SQLite" repository = "https://github.com/jgallagher/rusqlite" diff --git a/Changelog.md b/Changelog.md index 1450f0e..cf69389 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# Version 0.9.3 (2017-01-23) + +* Make `ToSqlOutput` itself implement `ToSql`. + # Version 0.9.2 (2017-01-22) * Bugfix: The `FromSql` impl for `i32` now returns an error instead of diff --git a/src/lib.rs b/src/lib.rs index 924d301..1a10816 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -908,7 +908,7 @@ impl<'conn> Statement<'conn> { ValueRef::Null => unsafe { ffi::sqlite3_bind_null(ptr, col) }, ValueRef::Integer(i) => unsafe { ffi::sqlite3_bind_int64(ptr, col, i) }, ValueRef::Real(r) => unsafe { ffi::sqlite3_bind_double(ptr, col, r) }, - ValueRef::Text(ref s) => unsafe { + ValueRef::Text(s) => unsafe { let length = s.len(); if length > ::std::i32::MAX as usize { ffi::SQLITE_TOOBIG @@ -922,7 +922,7 @@ impl<'conn> Statement<'conn> { ffi::sqlite3_bind_text(ptr, col, c_str.as_ptr(), length as c_int, destructor) } }, - ValueRef::Blob(ref b) => unsafe { + ValueRef::Blob(b) => unsafe { let length = b.len(); if length > ::std::i32::MAX as usize { ffi::SQLITE_TOOBIG diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index 32ad3a3..415ff27 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -38,9 +38,9 @@ impl Error for FromSqlError { #[cfg_attr(feature="clippy", allow(match_same_arms))] fn cause(&self) -> Option<&Error> { match *self { - FromSqlError::InvalidType => None, - FromSqlError::OutOfRange(_) => None, FromSqlError::Other(ref err) => err.cause(), + FromSqlError::InvalidType | + FromSqlError::OutOfRange(_) => None, } } } diff --git a/src/types/to_sql.rs b/src/types/to_sql.rs index 3738217..9dfa6b9 100644 --- a/src/types/to_sql.rs +++ b/src/types/to_sql.rs @@ -28,6 +28,18 @@ impl<'a, T: Into> From for ToSqlOutput<'a> { } } +impl<'a> ToSql for ToSqlOutput<'a> { + fn to_sql(&self) -> Result { + Ok(match *self { + ToSqlOutput::Borrowed(v) => ToSqlOutput::Borrowed(v), + ToSqlOutput::Owned(ref v) => ToSqlOutput::Borrowed(ValueRef::from(v)), + + #[cfg(feature = "blob")] + ToSqlOutput::ZeroBlob(i) => ToSqlOutput::ZeroBlob(i), + }) + } +} + /// A trait for types that can be converted into SQLite values. pub trait ToSql { fn to_sql(&self) -> Result; diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index 16b8611..96a7641 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -54,7 +54,7 @@ impl<'a> ValueRef<'a> { /// `Err(Error::InvalidColumnType)`. pub fn as_str(&self) -> FromSqlResult<&str> { match *self { - ValueRef::Text(ref t) => Ok(t), + ValueRef::Text(t) => Ok(t), _ => Err(FromSqlError::InvalidType), } } @@ -63,7 +63,7 @@ impl<'a> ValueRef<'a> { /// `Err(Error::InvalidColumnType)`. pub fn as_blob(&self) -> FromSqlResult<&[u8]> { match *self { - ValueRef::Blob(ref b) => Ok(b), + ValueRef::Blob(b) => Ok(b), _ => Err(FromSqlError::InvalidType), } }