mirror of
https://github.com/isar/rusqlite.git
synced 2025-10-26 03:08:57 +08:00
Merge branch 'master' into gwenn-convenient
This commit is contained in:
127
src/error.rs
127
src/error.rs
@@ -56,6 +56,9 @@ pub enum Error {
|
||||
/// that column cannot be converted to the requested Rust type.
|
||||
InvalidColumnType,
|
||||
|
||||
/// Error when a query that was expected to insert one row did not insert any or insert many.
|
||||
QueryInsertedRows(c_int),
|
||||
|
||||
/// Error returned by `functions::Context::get` when the function argument cannot be converted
|
||||
/// to the requested type.
|
||||
#[cfg(feature = "functions")]
|
||||
@@ -66,9 +69,6 @@ pub enum Error {
|
||||
#[cfg(feature = "functions")]
|
||||
#[allow(dead_code)]
|
||||
UserFunctionError(Box<error::Error + Send + Sync>),
|
||||
|
||||
/// Error when a query that was expected to insert one row did not insert any or insert many.
|
||||
QueryInsertedRows(c_int),
|
||||
}
|
||||
|
||||
impl From<str::Utf8Error> for Error {
|
||||
@@ -85,81 +85,90 @@ impl From<::std::ffi::NulError> for Error {
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Error::SqliteFailure(ref err, None) => err.fmt(f),
|
||||
&Error::SqliteFailure(_, Some(ref s)) => write!(f, "{}", s),
|
||||
&Error::SqliteSingleThreadedMode => write!(f, "SQLite was compiled or configured for single-threaded use only"),
|
||||
&Error::FromSqlConversionFailure(ref err) => err.fmt(f),
|
||||
&Error::Utf8Error(ref err) => err.fmt(f),
|
||||
&Error::NulError(ref err) => err.fmt(f),
|
||||
&Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {}", name),
|
||||
&Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
|
||||
&Error::ExecuteReturnedResults => write!(f, "Execute returned results - did you mean to call query?"),
|
||||
&Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
|
||||
&Error::GetFromStaleRow => write!(f, "Attempted to get a value from a stale row"),
|
||||
&Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {}", i),
|
||||
&Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {}", name),
|
||||
&Error::InvalidColumnType => write!(f, "Invalid column type"),
|
||||
match *self {
|
||||
Error::SqliteFailure(ref err, None) => err.fmt(f),
|
||||
Error::SqliteFailure(_, Some(ref s)) => write!(f, "{}", s),
|
||||
Error::SqliteSingleThreadedMode => {
|
||||
write!(f,
|
||||
"SQLite was compiled or configured for single-threaded use only")
|
||||
}
|
||||
Error::FromSqlConversionFailure(ref err) => err.fmt(f),
|
||||
Error::Utf8Error(ref err) => err.fmt(f),
|
||||
Error::NulError(ref err) => err.fmt(f),
|
||||
Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {}", name),
|
||||
Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
|
||||
Error::ExecuteReturnedResults => {
|
||||
write!(f, "Execute returned results - did you mean to call query?")
|
||||
}
|
||||
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
|
||||
Error::GetFromStaleRow => write!(f, "Attempted to get a value from a stale row"),
|
||||
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {}", i),
|
||||
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {}", name),
|
||||
Error::InvalidColumnType => write!(f, "Invalid column type"),
|
||||
Error::QueryInsertedRows(i) => write!(f, "Query inserted {} rows", i),
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
&Error::InvalidFunctionParameterType => write!(f, "Invalid function parameter type"),
|
||||
Error::InvalidFunctionParameterType => write!(f, "Invalid function parameter type"),
|
||||
#[cfg(feature = "functions")]
|
||||
&Error::UserFunctionError(ref err) => err.fmt(f),
|
||||
|
||||
&Error::QueryInsertedRows(i) => write!(f, "Query inserted {} rows", i),
|
||||
Error::UserFunctionError(ref err) => err.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
&Error::SqliteFailure(ref err, None) => err.description(),
|
||||
&Error::SqliteFailure(_, Some(ref s)) => s,
|
||||
&Error::SqliteSingleThreadedMode => "SQLite was compiled or configured for single-threaded use only",
|
||||
&Error::FromSqlConversionFailure(ref err) => err.description(),
|
||||
&Error::Utf8Error(ref err) => err.description(),
|
||||
&Error::InvalidParameterName(_) => "invalid parameter name",
|
||||
&Error::NulError(ref err) => err.description(),
|
||||
&Error::InvalidPath(_) => "invalid path",
|
||||
&Error::ExecuteReturnedResults => "execute returned results - did you mean to call query?",
|
||||
&Error::QueryReturnedNoRows => "query returned no rows",
|
||||
&Error::GetFromStaleRow => "attempted to get a value from a stale row",
|
||||
&Error::InvalidColumnIndex(_) => "invalid column index",
|
||||
&Error::InvalidColumnName(_) => "invalid column name",
|
||||
&Error::InvalidColumnType => "invalid column type",
|
||||
match *self {
|
||||
Error::SqliteFailure(ref err, None) => err.description(),
|
||||
Error::SqliteFailure(_, Some(ref s)) => s,
|
||||
Error::SqliteSingleThreadedMode => {
|
||||
"SQLite was compiled or configured for single-threaded use only"
|
||||
}
|
||||
Error::FromSqlConversionFailure(ref err) => err.description(),
|
||||
Error::Utf8Error(ref err) => err.description(),
|
||||
Error::InvalidParameterName(_) => "invalid parameter name",
|
||||
Error::NulError(ref err) => err.description(),
|
||||
Error::InvalidPath(_) => "invalid path",
|
||||
Error::ExecuteReturnedResults => {
|
||||
"execute returned results - did you mean to call query?"
|
||||
}
|
||||
Error::QueryReturnedNoRows => "query returned no rows",
|
||||
Error::GetFromStaleRow => "attempted to get a value from a stale row",
|
||||
Error::InvalidColumnIndex(_) => "invalid column index",
|
||||
Error::InvalidColumnName(_) => "invalid column name",
|
||||
Error::InvalidColumnType => "invalid column type",
|
||||
Error::QueryInsertedRows(_) => "query inserted zero or more than one row",
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
&Error::InvalidFunctionParameterType => "invalid function parameter type",
|
||||
Error::InvalidFunctionParameterType => "invalid function parameter type",
|
||||
#[cfg(feature = "functions")]
|
||||
&Error::UserFunctionError(ref err) => err.description(),
|
||||
|
||||
&Error::QueryInsertedRows(_) => "query inserted zero or more than one row",
|
||||
Error::UserFunctionError(ref err) => err.description(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="clippy", allow(match_same_arms))]
|
||||
fn cause(&self) -> Option<&error::Error> {
|
||||
match self {
|
||||
&Error::SqliteFailure(ref err, _) => Some(err),
|
||||
&Error::SqliteSingleThreadedMode => None,
|
||||
&Error::FromSqlConversionFailure(ref err) => Some(&**err),
|
||||
&Error::Utf8Error(ref err) => Some(err),
|
||||
&Error::NulError(ref err) => Some(err),
|
||||
&Error::InvalidParameterName(_) => None,
|
||||
&Error::InvalidPath(_) => None,
|
||||
&Error::ExecuteReturnedResults => None,
|
||||
&Error::QueryReturnedNoRows => None,
|
||||
&Error::GetFromStaleRow => None,
|
||||
&Error::InvalidColumnIndex(_) => None,
|
||||
&Error::InvalidColumnName(_) => None,
|
||||
&Error::InvalidColumnType => None,
|
||||
match *self {
|
||||
Error::SqliteFailure(ref err, _) => Some(err),
|
||||
Error::FromSqlConversionFailure(ref err) => Some(&**err),
|
||||
Error::Utf8Error(ref err) => Some(err),
|
||||
Error::NulError(ref err) => Some(err),
|
||||
|
||||
Error::SqliteSingleThreadedMode |
|
||||
Error::InvalidParameterName(_) |
|
||||
Error::ExecuteReturnedResults |
|
||||
Error::QueryReturnedNoRows |
|
||||
Error::GetFromStaleRow |
|
||||
Error::InvalidColumnIndex(_) |
|
||||
Error::InvalidColumnName(_) |
|
||||
Error::InvalidColumnType |
|
||||
Error::InvalidPath(_) => None,
|
||||
Error::QueryInsertedRows(_) => None,
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
&Error::InvalidFunctionParameterType => None,
|
||||
#[cfg(feature = "functions")]
|
||||
&Error::UserFunctionError(ref err) => Some(&**err),
|
||||
Error::InvalidFunctionParameterType => None,
|
||||
|
||||
&Error::QueryInsertedRows(_) => None,
|
||||
#[cfg(feature = "functions")]
|
||||
Error::UserFunctionError(ref err) => Some(&**err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user