Put something into the msg object if we fail to get a valid string out of the db

This commit is contained in:
jikstra
2019-08-10 16:47:38 +02:00
parent b7174783f1
commit 966bb2271a
2 changed files with 26 additions and 6 deletions

View File

@@ -436,8 +436,12 @@ pub unsafe fn dc_msg_get_timestamp(msg: *const dc_msg_t) -> i64 {
};
}
//pub fn dc_msg_load_from_db_r(context: &'a Context, id: u32) -> Result<mut dc_msg_t> {
//}
pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id: u32) -> bool {
if msg.is_null() {
println!("xxx msg is null {}", id);
return false;
}
@@ -472,7 +476,15 @@ pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id:
(*msg).type_0 = row.get(12)?;
(*msg).state = row.get(13)?;
(*msg).is_dc_message = row.get(14)?;
(*msg).text = row.get::<_, Option<String>>(15)?;
println!("Before2 text: {}", id);
(*msg).text = match row.get(15) {
Ok(text) => Some(text),
Err(e) => {
warn!(context, 0, "dc_msg_load_from_db: could not get text column for id {} because of {}", id, e);
Some("[ Could not read from db ]".to_string())
}
};
println!("After text: {}", id);
(*msg).param = row.get::<_, String>(16)?.parse().unwrap_or_default();
(*msg).starred = row.get(17)?;
(*msg).hidden = row.get(18)?;
@@ -491,8 +503,12 @@ pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id:
Ok(())
}
});
res.is_ok()
// HERE WE ARE!
if let Err(e) = res {
warn!(context, 0, "Error in msg_load_from_db for id {} because of {}", id, e);
return false;
}
true
}
pub unsafe fn dc_get_mime_headers(context: &Context, msg_id: uint32_t) -> *mut libc::c_char {
@@ -628,14 +644,17 @@ pub fn dc_star_msgs(
}
pub unsafe fn dc_get_msg<'a>(context: &'a Context, msg_id: uint32_t) -> *mut dc_msg_t<'a> {
let mut success: libc::c_int = 0i32;
let mut success = false;
let obj: *mut dc_msg_t = dc_msg_new_untyped(context);
if dc_msg_load_from_db(obj, context, msg_id) {
success = 1i32
success = true
}
if 0 != success {
if success {
obj
} else {
println!("No success for {}", msg_id);
dc_msg_unref(obj);
0 as *mut dc_msg_t
}