Simplify InvalidType

This commit is contained in:
gwenn 2016-05-30 21:20:07 +02:00
parent fb19e718cf
commit 91dc30b04d
6 changed files with 12 additions and 14 deletions

View File

@ -55,7 +55,7 @@ pub enum Error {
/// Error when an SQLite value is requested, but the type of the result cannot be converted to the /// Error when an SQLite value is requested, but the type of the result cannot be converted to the
/// requested Rust type. /// requested Rust type.
InvalidType(Type), InvalidType,
/// Error when a query that was expected to insert one row did not insert any or insert many. /// Error when a query that was expected to insert one row did not insert any or insert many.
StatementChangedRows(c_int), StatementChangedRows(c_int),
@ -111,9 +111,7 @@ impl fmt::Display for Error {
Error::InvalidColumnType(i, ref t) => { Error::InvalidColumnType(i, ref t) => {
write!(f, "Invalid column type {} at index: {}", t, i) write!(f, "Invalid column type {} at index: {}", t, i)
} }
Error::InvalidType(ref t) => { Error::InvalidType => write!(f, "Invalid type"),
write!(f, "Invalid type {}", t)
}
Error::StatementChangedRows(i) => write!(f, "Query changed {} rows", i), Error::StatementChangedRows(i) => write!(f, "Query changed {} rows", i),
Error::StatementFailedToInsertRow => write!(f, "Statement failed to insert new row"), Error::StatementFailedToInsertRow => write!(f, "Statement failed to insert new row"),
@ -147,7 +145,7 @@ impl error::Error for Error {
Error::InvalidColumnIndex(_) => "invalid column index", Error::InvalidColumnIndex(_) => "invalid column index",
Error::InvalidColumnName(_) => "invalid column name", Error::InvalidColumnName(_) => "invalid column name",
Error::InvalidColumnType(_, _) => "invalid column type", Error::InvalidColumnType(_, _) => "invalid column type",
Error::InvalidType(_) => "invalid type", Error::InvalidType => "invalid type",
Error::StatementChangedRows(_) => "query inserted zero or more than one row", Error::StatementChangedRows(_) => "query inserted zero or more than one row",
Error::StatementFailedToInsertRow => "statement failed to insert new row", Error::StatementFailedToInsertRow => "statement failed to insert new row",
@ -173,7 +171,7 @@ impl error::Error for Error {
Error::InvalidColumnIndex(_) | Error::InvalidColumnIndex(_) |
Error::InvalidColumnName(_) | Error::InvalidColumnName(_) |
Error::InvalidColumnType(_, _) | Error::InvalidColumnType(_, _) |
Error::InvalidType(_) | Error::InvalidType |
Error::InvalidPath(_) | Error::InvalidPath(_) |
Error::StatementChangedRows(_) | Error::StatementChangedRows(_) |
Error::StatementFailedToInsertRow => None, Error::StatementFailedToInsertRow => None,

View File

@ -218,7 +218,7 @@ impl<'a> Context<'a> {
let arg = self.args[idx]; let arg = self.args[idx];
let value = unsafe { ValueRef::from_value(arg) }; let value = unsafe { ValueRef::from_value(arg) };
FromSql::column_result(value).map_err(|err| match err { FromSql::column_result(value).map_err(|err| match err {
Error::InvalidType(t) => Error::InvalidFunctionParameterType(idx, t), Error::InvalidType => Error::InvalidFunctionParameterType(idx, value.data_type()),
_ => err, _ => err,
}) })
} }

View File

@ -1067,7 +1067,7 @@ impl<'a, 'stmt> Row<'a, 'stmt> {
let idx = try!(idx.idx(self.stmt)); let idx = try!(idx.idx(self.stmt));
let value = unsafe { ValueRef::new(&self.stmt.stmt, idx) }; let value = unsafe { ValueRef::new(&self.stmt.stmt, idx) };
FromSql::column_result(value).map_err(|err| match err { FromSql::column_result(value).map_err(|err| match err {
Error::InvalidType(t) => Error::InvalidColumnType(idx, t), Error::InvalidType => Error::InvalidColumnType(idx, value.data_type()),
_ => err, _ => err,
}) })
} }

View File

@ -24,7 +24,7 @@ impl FromSql for f64 {
match value { match value {
ValueRef::Integer(i) => Ok(i as f64), ValueRef::Integer(i) => Ok(i as f64),
ValueRef::Real(f) => Ok(f), ValueRef::Real(f) => Ok(f),
_ => Err(Error::InvalidType(value.data_type())), _ => Err(Error::InvalidType),
} }
} }
} }

View File

@ -23,7 +23,7 @@ impl FromSql for Value {
match value { match value {
ValueRef::Text(ref s) => serde_json::from_str(s), ValueRef::Text(ref s) => serde_json::from_str(s),
ValueRef::Blob(ref b) => serde_json::from_slice(b), ValueRef::Blob(ref b) => serde_json::from_slice(b),
_ => return Err(Error::InvalidType(value.data_type())), _ => return Err(Error::InvalidType),
} }
.map_err(|err| Error::FromSqlConversionFailure(Box::new(err))) .map_err(|err| Error::FromSqlConversionFailure(Box::new(err)))
} }

View File

@ -38,7 +38,7 @@ impl<'a> ValueRef<'a> {
pub fn as_i64(&self) -> Result<i64> { pub fn as_i64(&self) -> Result<i64> {
match *self { match *self {
ValueRef::Integer(i) => Ok(i), ValueRef::Integer(i) => Ok(i),
_ => Err(Error::InvalidType(self.data_type())), _ => Err(Error::InvalidType),
} }
} }
@ -47,7 +47,7 @@ impl<'a> ValueRef<'a> {
pub fn as_f64(&self) -> Result<f64> { pub fn as_f64(&self) -> Result<f64> {
match *self { match *self {
ValueRef::Real(f) => Ok(f), ValueRef::Real(f) => Ok(f),
_ => Err(Error::InvalidType(self.data_type())), _ => Err(Error::InvalidType),
} }
} }
@ -56,7 +56,7 @@ impl<'a> ValueRef<'a> {
pub fn as_str(&self) -> Result<&str> { pub fn as_str(&self) -> Result<&str> {
match *self { match *self {
ValueRef::Text(ref t) => Ok(t), ValueRef::Text(ref t) => Ok(t),
_ => Err(Error::InvalidType(self.data_type())), _ => Err(Error::InvalidType),
} }
} }
@ -65,7 +65,7 @@ impl<'a> ValueRef<'a> {
pub fn as_blob(&self) -> Result<&[u8]> { pub fn as_blob(&self) -> Result<&[u8]> {
match *self { match *self {
ValueRef::Blob(ref b) => Ok(b), ValueRef::Blob(ref b) => Ok(b),
_ => Err(Error::InvalidType(self.data_type())), _ => Err(Error::InvalidType),
} }
} }
} }