Compare commits
4 Commits
62582ee055
...
66e7bc22cf
| Author | SHA1 | Date | |
|---|---|---|---|
| 66e7bc22cf | |||
| 35f83c376f | |||
| 3f3a2df072 | |||
| c3d4e63d73 |
@@ -30,12 +30,8 @@ fn from_condition(
|
||||
(_, Condition::Bool(_)) => return Err(FailedTo::ComposeFilter),
|
||||
// SIGNED INT
|
||||
(Comparison::Equal, Condition::SignedInt(_)) => compose_fragment("value_int", "=", i),
|
||||
(Comparison::Greater, Condition::SignedInt(_)) => {
|
||||
compose_fragment("value_int", ">", i)
|
||||
}
|
||||
(Comparison::Lesser, Condition::SignedInt(_)) => {
|
||||
compose_fragment("value_int", "<", i)
|
||||
}
|
||||
(Comparison::Greater, Condition::SignedInt(_)) => compose_fragment("value_int", ">", i),
|
||||
(Comparison::Lesser, Condition::SignedInt(_)) => compose_fragment("value_int", "<", i),
|
||||
(Comparison::GreaterOrEqual, Condition::SignedInt(_)) => {
|
||||
compose_fragment("value_int", ">=", i)
|
||||
}
|
||||
@@ -44,15 +40,9 @@ fn from_condition(
|
||||
}
|
||||
(_, Condition::SignedInt(_)) => return Err(FailedTo::ComposeFilter),
|
||||
// UNSIGNED INT
|
||||
(Comparison::Equal, Condition::UnsignedInt(_)) => {
|
||||
compose_fragment("value_uint", "=", i)
|
||||
}
|
||||
(Comparison::Greater, Condition::UnsignedInt(_)) => {
|
||||
compose_fragment("value_uint", ">", i)
|
||||
}
|
||||
(Comparison::Lesser, Condition::UnsignedInt(_)) => {
|
||||
compose_fragment("value_uint", "<", i)
|
||||
}
|
||||
(Comparison::Equal, Condition::UnsignedInt(_)) => compose_fragment("value_uint", "=", i),
|
||||
(Comparison::Greater, Condition::UnsignedInt(_)) => compose_fragment("value_uint", ">", i),
|
||||
(Comparison::Lesser, Condition::UnsignedInt(_)) => compose_fragment("value_uint", "<", i),
|
||||
(Comparison::GreaterOrEqual, Condition::UnsignedInt(_)) => {
|
||||
compose_fragment("value_uint", ">=", i)
|
||||
}
|
||||
@@ -64,12 +54,8 @@ fn from_condition(
|
||||
(Comparison::Equal, Condition::Real(_)) => compose_fragment("value_real", "=", i),
|
||||
(Comparison::Greater, Condition::Real(_)) => compose_fragment("value_real", ">", i),
|
||||
(Comparison::Lesser, Condition::Real(_)) => compose_fragment("value_real", "<", i),
|
||||
(Comparison::GreaterOrEqual, Condition::Real(_)) => {
|
||||
compose_fragment("value_real", ">=", i)
|
||||
}
|
||||
(Comparison::LesserOrEqual, Condition::Real(_)) => {
|
||||
compose_fragment("value_real", "<=", i)
|
||||
}
|
||||
(Comparison::GreaterOrEqual, Condition::Real(_)) => compose_fragment("value_real", ">=", i),
|
||||
(Comparison::LesserOrEqual, Condition::Real(_)) => compose_fragment("value_real", "<=", i),
|
||||
(_, Condition::Real(_)) => return Err(FailedTo::ComposeFilter),
|
||||
// TEXT
|
||||
(Comparison::IsExactly, Condition::Text(_)) => compose_fragment("value_text", "=", i),
|
||||
|
||||
@@ -54,3 +54,35 @@ impl From<sqlite::FailedTo> for FailedTo {
|
||||
Self::SQLite(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for FailedTo {}
|
||||
|
||||
impl std::fmt::Display for FailedTo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||
match self {
|
||||
FailedTo::ComposeFilter => write!(f, "Failed to compose filter statement"),
|
||||
FailedTo::ConvertEntity => write!(f, "Failed to convert from Entity to type"),
|
||||
FailedTo::ConvertObject => write!(f, "Failed to convert from type to Entity"),
|
||||
FailedTo::ConvertValue => write!(f, "Failed to convert from Value to type"),
|
||||
FailedTo::ExecutePredicate(errors) => {
|
||||
write!(f, "Failed to execute predicate: ")?;
|
||||
for (i, err) in errors.iter().enumerate() {
|
||||
if i > 0 {
|
||||
write!(f, "; ")?;
|
||||
}
|
||||
write!(f, "{}", err)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
FailedTo::InitDatabase => write!(f, "Failed to initialize the database"),
|
||||
FailedTo::LoadFromDB => write!(f, "Failed to load data from the database"),
|
||||
FailedTo::LockCatalog => {
|
||||
write!(f, "Failed to lock catalog in a multithread environment")
|
||||
}
|
||||
FailedTo::MapAttribute => write!(f, "Failed to map a database row to an attribute"),
|
||||
FailedTo::MapEntity => write!(f, "Failed to map a database row to an entity"),
|
||||
FailedTo::PersistCatalog => write!(f, "Failed to persist the catalog to the database"),
|
||||
FailedTo::SQLite(e) => write!(f, "SQLite error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,3 +18,33 @@ pub enum FailedTo {
|
||||
/// Failed to prepare a SQL statement for execution.
|
||||
PrepareStatement(rusqlite::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for FailedTo {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
FailedTo::BeginTransaction(e) => Some(e),
|
||||
FailedTo::BuildStatement => None,
|
||||
FailedTo::CommitTransaction(e) => Some(e),
|
||||
FailedTo::ExecuteBatch(e) => Some(e),
|
||||
FailedTo::ExecuteQuery(e) => Some(e),
|
||||
FailedTo::ExecuteStatement(e) => Some(e),
|
||||
FailedTo::OpenConnection(e) => Some(e),
|
||||
FailedTo::PrepareStatement(e) => Some(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for FailedTo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||
match self {
|
||||
FailedTo::BeginTransaction(e) => write!(f, "Failed to begin transaction: {}", e),
|
||||
FailedTo::BuildStatement => write!(f, "Failed to build SQL statement"),
|
||||
FailedTo::CommitTransaction(e) => write!(f, "Failed to commit transaction: {}", e),
|
||||
FailedTo::ExecuteBatch(e) => write!(f, "Failed to execute batch: {}", e),
|
||||
FailedTo::ExecuteQuery(e) => write!(f, "Failed to execute query: {}", e),
|
||||
FailedTo::ExecuteStatement(e) => write!(f, "Failed to execute statement: {}", e),
|
||||
FailedTo::OpenConnection(e) => write!(f, "Failed to open connection: {}", e),
|
||||
FailedTo::PrepareStatement(e) => write!(f, "Failed to prepare statement: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user