Resultify sql.open()

This commit is contained in:
Hocuri
2020-09-16 13:45:32 +02:00
parent 0a5d1e5551
commit f9cc3cbef0
3 changed files with 40 additions and 33 deletions

View File

@@ -14,6 +14,7 @@ use crate::constants::{ShowEmails, DC_CHAT_ID_TRASH};
use crate::context::Context;
use crate::dc_tools::*;
use crate::ephemeral::start_ephemeral_timers;
use crate::error::format_err;
use crate::param::*;
use crate::peerstate::*;
@@ -78,17 +79,22 @@ impl Sql {
}
// return true on success, false on failure
pub async fn open<T: AsRef<Path>>(&self, context: &Context, dbfile: T, readonly: bool) -> bool {
match open(context, self, dbfile, readonly).await {
Ok(_) => true,
Err(err) => match err.downcast_ref::<Error>() {
Some(Error::SqlAlreadyOpen) => false,
pub async fn open<T: AsRef<Path>>(
&self,
context: &Context,
dbfile: T,
readonly: bool,
) -> crate::error::Result<()> {
let res = open(context, self, dbfile, readonly).await;
if let Err(err) = &res {
match err.downcast_ref::<Error>() {
Some(Error::SqlAlreadyOpen) => {}
_ => {
self.close().await;
false
}
},
}
}
res.map_err(|e| format_err!("Could not open db: {}", e))
}
pub async fn execute<S: AsRef<str>>(