From faa31f599a18fd0c4cc848cda3b40f7fef64f85c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 1 Jun 2020 17:08:57 +0200 Subject: [PATCH] Better anticipation of errors --- src/helpers/database.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/helpers/database.rs b/src/helpers/database.rs index e9df6e5..1e62c9e 100644 --- a/src/helpers/database.rs +++ b/src/helpers/database.rs @@ -117,7 +117,7 @@ impl QueryInfo { /// Query just a row pub fn query_row ProcessRowResult>(self, process_function: F) - -> Result> { + -> Result> { query_row(self, process_function) } @@ -230,7 +230,7 @@ impl<'a> RowResult<'a> { /// Get a MYSQL date as a timestamp pub fn get_date_as_time(&self, name: &str) -> ResultBoxError { let value = self.row.get_opt(self.find_col(name)?); - let value : Value = value.ok_or(ExecError(format!("Could not find date field {} !", name)))??; + let value: Value = value.ok_or(ExecError(format!("Could not find date field {} !", name)))??; // Check if it is a date if let Value::Date(year, month, day, hour, minutes, seconds, mic_secs) = value { @@ -248,11 +248,14 @@ impl<'a> RowResult<'a> { /// Query a single row of the database pub fn query_row ProcessRowResult>(mut info: QueryInfo, process_function: F) -> Result> { + let table = info.table.clone(); + info.limit = 1; let mut list = query(info, process_function)?; match list.len() { - 0 => Err(ExecError::boxed_new("Request did not return a result!")), + 0 => Err(ExecError::boxed_string( + format!("Database query did not return a result: (table: {}) !", table))), _ => Ok(list.remove(0)) } } @@ -434,7 +437,7 @@ pub fn delete(query: DeleteQuery) -> ResultBoxError<()> { get_connection()?.exec_drop( query_sql, - query.conditions.values().collect::>() + query.conditions.values().collect::>(), )?; Ok(())