fix: allow concurrent access to dc_sqlite3_t

This commit is contained in:
dignifiedquire
2019-05-02 23:33:00 +02:00
parent 1a0808e243
commit e187f0f250
26 changed files with 383 additions and 440 deletions

View File

@@ -124,7 +124,7 @@ pub unsafe fn dc_block_chat(
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE chats SET blocked=? WHERE id=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_int(stmt, 1i32, new_blocking);
@@ -140,7 +140,7 @@ pub unsafe fn dc_chat_load_from_db(mut chat: *mut dc_chat_t, mut chat_id: uint32
stmt =
dc_sqlite3_prepare(
(*chat).context,
&mut (*chat).context.sql.lock().unwrap(),
&(*chat).context.sql.read().unwrap(),
b"SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, c.blocked, c.gossiped_timestamp, c.locations_send_until FROM chats c WHERE c.id=?;\x00"
as *const u8 as *const libc::c_char
);
@@ -278,7 +278,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
if !ret_chat_blocked.is_null() {
*ret_chat_blocked = 0i32
}
if context.sql.lock().unwrap().cobj.is_null() {
if context.sql.read().unwrap().cobj.is_null() {
return;
}
if contact_id == 0i32 as libc::c_uint {
@@ -295,7 +295,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
return;
}
contact = dc_contact_new(context);
if !(0 == dc_contact_load_from_db(contact, &mut context.sql.lock().unwrap(), contact_id)) {
if !(0 == dc_contact_load_from_db(contact, &context.sql.clone().read().unwrap(), contact_id)) {
chat_name =
if !(*contact).name.is_null() && 0 != *(*contact).name.offset(0isize) as libc::c_int {
(*contact).name
@@ -327,12 +327,12 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
);
} else {
};
stmt = dc_sqlite3_prepare(context, &mut context.sql.lock().unwrap(), q);
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q);
if !stmt.is_null() {
if !(sqlite3_step(stmt) != 101i32) {
chat_id = dc_sqlite3_get_rowid(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"chats\x00" as *const u8 as *const libc::c_char,
b"grpid\x00" as *const u8 as *const libc::c_char,
(*contact).addr,
@@ -347,7 +347,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
chat_id,
contact_id,
);
stmt = dc_sqlite3_prepare(context, &mut context.sql.lock().unwrap(), q);
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q);
if !(sqlite3_step(stmt) != 101i32) {
sqlite3_free(q as *mut libc::c_void);
q = 0 as *mut libc::c_char;
@@ -381,13 +381,13 @@ pub unsafe fn dc_lookup_real_nchat_by_contact_id(
if !ret_chat_blocked.is_null() {
*ret_chat_blocked = 0i32
}
if context.sql.lock().unwrap().cobj.is_null() {
if context.sql.clone().read().unwrap().cobj.is_null() {
return;
}
stmt =
dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT c.id, c.blocked FROM chats c INNER JOIN chats_contacts j ON c.id=j.chat_id WHERE c.type=100 AND c.id>9 AND j.contact_id=?;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, contact_id as libc::c_int);
@@ -569,7 +569,7 @@ unsafe fn prepare_msg_raw(
} else {
let mut from: *mut libc::c_char = dc_sqlite3_get_config(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char,
);
@@ -592,7 +592,7 @@ unsafe fn prepare_msg_raw(
if (*chat).type_0 == 100i32 {
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT contact_id FROM chats_contacts WHERE chat_id=?;\x00" as *const u8
as *const libc::c_char,
);
@@ -631,7 +631,7 @@ unsafe fn prepare_msg_raw(
do_guarantee_e2ee = 0i32;
e2ee_enabled = dc_sqlite3_get_config_int(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"e2ee_enabled\x00" as *const u8 as *const libc::c_char,
1i32,
);
@@ -640,7 +640,7 @@ unsafe fn prepare_msg_raw(
let mut can_encrypt: libc::c_int = 1i32;
let mut all_mutual: libc::c_int = 1i32;
stmt =
dc_sqlite3_prepare(context, &mut context.sql.lock().unwrap(),
dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(),
b"SELECT ps.prefer_encrypted, c.addr FROM chats_contacts cc LEFT JOIN contacts c ON cc.contact_id=c.id LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE cc.chat_id=? AND cc.contact_id>9;\x00"
as *const u8 as
*const libc::c_char);
@@ -684,7 +684,7 @@ unsafe fn prepare_msg_raw(
} else if 0
!= last_msg_in_chat_encrypted(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
(*chat).id,
)
{
@@ -752,7 +752,7 @@ unsafe fn prepare_msg_raw(
if 0 != dc_param_exists((*msg).param, DC_PARAM_SET_LATITUDE as libc::c_int) {
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"INSERT INTO locations \
(timestamp,from_id,chat_id, latitude,longitude,independent)\
VALUES (?,?,?, ?,?,1);\x00" as *const u8
@@ -785,7 +785,7 @@ unsafe fn prepare_msg_raw(
location_id = dc_sqlite3_get_rowid2(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"locations\x00" as *const u8 as *const libc::c_char,
b"timestamp\x00" as *const u8 as *const libc::c_char,
timestamp as u64,
@@ -798,7 +798,7 @@ unsafe fn prepare_msg_raw(
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"INSERT INTO msgs (rfc724_mid, chat_id, from_id, to_id, timestamp, type, state, txt, param, hidden, mime_in_reply_to, mime_references, location_id) VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?);\x00"
as *const u8 as
*const libc::c_char);
@@ -836,7 +836,7 @@ unsafe fn prepare_msg_raw(
} else {
msg_id = dc_sqlite3_get_rowid(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"msgs\x00" as *const u8 as *const libc::c_char,
b"rfc724_mid\x00" as *const u8 as *const libc::c_char,
new_rfc724_mid,
@@ -870,7 +870,7 @@ unsafe fn get_parent_mime_headers(
{
stmt =
dc_sqlite3_prepare(
(*chat).context,&mut (*chat).context.sql.lock().unwrap(),
(*chat).context,&mut (*chat).context.sql.clone().read().unwrap(),
b"SELECT rfc724_mid, mime_in_reply_to, mime_references FROM msgs WHERE timestamp=(SELECT max(timestamp) FROM msgs WHERE chat_id=? AND from_id!=?);\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, (*chat).id as libc::c_int);
@@ -886,7 +886,7 @@ unsafe fn get_parent_mime_headers(
if 0 == success {
stmt =
dc_sqlite3_prepare(
(*chat).context,&mut (*chat).context.sql.lock().unwrap(),
(*chat).context,&mut (*chat).context.sql.clone().read().unwrap(),
b"SELECT rfc724_mid, mime_in_reply_to, mime_references FROM msgs WHERE timestamp=(SELECT min(timestamp) FROM msgs WHERE chat_id=? AND from_id==?);\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, (*chat).id as libc::c_int);
@@ -916,7 +916,7 @@ pub unsafe fn dc_chat_is_self_talk(mut chat: *const dc_chat_t) -> libc::c_int {
******************************************************************************/
unsafe fn last_msg_in_chat_encrypted(
context: &dc_context_t,
sql: &mut dc_sqlite3_t,
sql: &dc_sqlite3_t,
chat_id: uint32_t,
) -> libc::c_int {
let mut last_is_encrypted: libc::c_int = 0i32;
@@ -944,7 +944,7 @@ pub unsafe fn dc_chat_update_param(mut chat: *mut dc_chat_t) -> libc::c_int {
let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
(*chat).context,
&mut (*chat).context.sql.lock().unwrap(),
&mut (*chat).context.sql.clone().read().unwrap(),
b"UPDATE chats SET param=? WHERE id=?\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_text(stmt, 1i32, (*(*chat).param).packed, -1i32, None);
@@ -969,7 +969,7 @@ pub unsafe fn dc_is_contact_in_chat(
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT contact_id FROM chats_contacts WHERE chat_id=? AND contact_id=?;\x00" as *const u8
as *const libc::c_char,
);
@@ -988,7 +988,7 @@ pub unsafe fn dc_is_contact_in_chat(
pub unsafe fn dc_unarchive_chat(mut context: &dc_context_t, mut chat_id: uint32_t) {
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE chats SET archived=0 WHERE id=?\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -1135,7 +1135,7 @@ unsafe fn set_draft_raw(
_ => {
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"INSERT INTO msgs (chat_id, from_id, timestamp, type, state, txt, param, hidden) VALUES (?,?,?, ?,?,?,?,?);\x00"
as *const u8 as
*const libc::c_char);
@@ -1171,7 +1171,7 @@ unsafe fn get_draft_msg_id(mut context: &dc_context_t, mut chat_id: uint32_t) ->
let mut draft_msg_id: uint32_t = 0i32 as uint32_t;
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT id FROM msgs WHERE chat_id=? AND state=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -1218,26 +1218,26 @@ pub unsafe fn dc_get_chat_msgs(
if chat_id == 1i32 as libc::c_uint {
let mut show_emails: libc::c_int = dc_sqlite3_get_config_int(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"show_emails\x00" as *const u8 as *const libc::c_char,
0i32,
);
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"SELECT m.id, m.timestamp FROM msgs m LEFT JOIN chats ON m.chat_id=chats.id LEFT JOIN contacts ON m.from_id=contacts.id WHERE m.from_id!=1 AND m.from_id!=2 AND m.hidden=0 AND chats.blocked=2 AND contacts.blocked=0 AND m.msgrmsg>=? ORDER BY m.timestamp,m.id;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, if show_emails == 2i32 { 0i32 } else { 1i32 });
} else if chat_id == 5i32 as libc::c_uint {
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"SELECT m.id, m.timestamp FROM msgs m LEFT JOIN contacts ct ON m.from_id=ct.id WHERE m.starred=1 AND m.hidden=0 AND ct.blocked=0 ORDER BY m.timestamp,m.id;\x00"
as *const u8 as *const libc::c_char)
} else {
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"SELECT m.id, m.timestamp FROM msgs m WHERE m.chat_id=? AND m.hidden=0 ORDER BY m.timestamp,m.id;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -1274,7 +1274,7 @@ pub unsafe fn dc_get_msg_cnt(mut context: &dc_context_t, mut chat_id: uint32_t)
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT COUNT(*) FROM msgs WHERE chat_id=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -1293,7 +1293,7 @@ pub unsafe fn dc_get_fresh_msg_cnt(
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT COUNT(*) FROM msgs WHERE state=10 AND hidden=0 AND chat_id=?;\x00"
as *const u8 as *const libc::c_char,
);
@@ -1310,7 +1310,7 @@ pub unsafe fn dc_marknoticed_chat(mut context: &dc_context_t, mut chat_id: uint3
check = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT id FROM msgs WHERE chat_id=? AND state=10;\x00" as *const u8
as *const libc::c_char,
);
@@ -1318,7 +1318,7 @@ pub unsafe fn dc_marknoticed_chat(mut context: &dc_context_t, mut chat_id: uint3
if !(sqlite3_step(check) != 100i32) {
update = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE msgs SET state=13 WHERE chat_id=? AND state=10;\x00" as *const u8
as *const libc::c_char,
);
@@ -1341,13 +1341,13 @@ pub unsafe fn dc_marknoticed_all_chats(mut context: &dc_context_t) {
check = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT id FROM msgs WHERE state=10;\x00" as *const u8 as *const libc::c_char,
);
if !(sqlite3_step(check) != 100i32) {
update = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE msgs SET state=13 WHERE state=10;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_step(update);
@@ -1372,7 +1372,7 @@ pub unsafe fn dc_get_chat_media(
let mut ret: *mut dc_array_t = dc_array_new(100i32 as size_t);
let mut stmt: *mut sqlite3_stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"SELECT id FROM msgs WHERE chat_id=? AND (type=? OR type=? OR type=?) ORDER BY timestamp, id;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -1464,7 +1464,7 @@ pub unsafe fn dc_archive_chat(
if 0 != archive {
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE msgs SET state=13 WHERE chat_id=? AND state=10;\x00" as *const u8
as *const libc::c_char,
);
@@ -1474,7 +1474,7 @@ pub unsafe fn dc_archive_chat(
}
let mut stmt_0: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE chats SET archived=? WHERE id=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_int(stmt_0, 1i32, archive);
@@ -1499,14 +1499,14 @@ pub unsafe fn dc_delete_chat(mut context: &dc_context_t, mut chat_id: uint32_t)
as *const u8 as *const libc::c_char,
chat_id,
);
if !(0 == dc_sqlite3_execute(context, &mut context.sql.lock().unwrap(), q3)) {
if !(0 == dc_sqlite3_execute(context, &context.sql.clone().read().unwrap(), q3)) {
sqlite3_free(q3 as *mut libc::c_void);
q3 = 0 as *mut libc::c_char;
q3 = sqlite3_mprintf(
b"DELETE FROM msgs WHERE chat_id=%i;\x00" as *const u8 as *const libc::c_char,
chat_id,
);
if !(0 == dc_sqlite3_execute(context, &mut context.sql.lock().unwrap(), q3)) {
if !(0 == dc_sqlite3_execute(context, &context.sql.clone().read().unwrap(), q3)) {
sqlite3_free(q3 as *mut libc::c_void);
q3 = 0 as *mut libc::c_char;
q3 = sqlite3_mprintf(
@@ -1514,7 +1514,8 @@ pub unsafe fn dc_delete_chat(mut context: &dc_context_t, mut chat_id: uint32_t)
as *const libc::c_char,
chat_id,
);
if !(0 == dc_sqlite3_execute(context, &mut context.sql.lock().unwrap(), q3)) {
if !(0 == dc_sqlite3_execute(context, &context.sql.clone().read().unwrap(), q3))
{
sqlite3_free(q3 as *mut libc::c_void);
q3 = 0 as *mut libc::c_char;
q3 = sqlite3_mprintf(
@@ -1522,7 +1523,12 @@ pub unsafe fn dc_delete_chat(mut context: &dc_context_t, mut chat_id: uint32_t)
as *const libc::c_char,
chat_id,
);
if !(0 == dc_sqlite3_execute(context, &mut context.sql.lock().unwrap(), q3))
if !(0
== dc_sqlite3_execute(
context,
&context.sql.clone().read().unwrap(),
q3,
))
{
sqlite3_free(q3 as *mut libc::c_void);
q3 = 0 as *mut libc::c_char;
@@ -1556,7 +1562,7 @@ pub unsafe fn dc_get_chat_contacts(
/* we could also create a list for all contacts in the deaddrop by searching contacts belonging to chats with chats.blocked=2, however, currently this is not needed */
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"SELECT cc.contact_id FROM chats_contacts cc LEFT JOIN contacts c ON c.id=cc.contact_id WHERE cc.chat_id=? ORDER BY c.id=1, LOWER(c.name||c.addr), c.id;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -1601,7 +1607,7 @@ pub unsafe fn dc_create_group_chat(
grpid = dc_create_id();
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"INSERT INTO chats (type, name, grpid, param) VALUES(?, ?, ?, \'U=1\');\x00" as *const u8
as *const libc::c_char,
);
@@ -1611,7 +1617,7 @@ pub unsafe fn dc_create_group_chat(
if !(sqlite3_step(stmt) != 101i32) {
chat_id = dc_sqlite3_get_rowid(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"chats\x00" as *const u8 as *const libc::c_char,
b"grpid\x00" as *const u8 as *const libc::c_char,
grpid,
@@ -1649,7 +1655,7 @@ pub unsafe fn dc_add_to_chat_contacts_table(
let mut ret: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)\x00" as *const u8
as *const libc::c_char,
);
@@ -1707,7 +1713,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
}
self_addr = dc_sqlite3_get_config(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char,
b"\x00" as *const u8 as *const libc::c_char,
);
@@ -1794,12 +1800,12 @@ unsafe fn real_group_exists(mut context: &dc_context_t, mut chat_id: uint32_t) -
// check if a group or a verified group exists under the given ID
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
let mut ret: libc::c_int = 0i32;
if (*context.sql.lock().unwrap()).cobj.is_null() || chat_id <= 9i32 as libc::c_uint {
if (*context.sql.clone().read().unwrap()).cobj.is_null() || chat_id <= 9i32 as libc::c_uint {
return 0i32;
}
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT id FROM chats WHERE id=? AND (type=120 OR type=130);\x00" as *const u8
as *const libc::c_char,
);
@@ -1829,7 +1835,7 @@ pub unsafe fn dc_set_gossiped_timestamp(
);
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE chats SET gossiped_timestamp=? WHERE id=?;\x00" as *const u8
as *const libc::c_char,
);
@@ -1844,7 +1850,7 @@ pub unsafe fn dc_set_gossiped_timestamp(
);
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"UPDATE chats SET gossiped_timestamp=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_int64(stmt, 1i32, timestamp as sqlite3_int64);
@@ -1918,7 +1924,7 @@ pub unsafe fn dc_remove_contact_from_chat(
chat_id,
contact_id,
);
if !(0 == dc_sqlite3_execute(context, &mut context.sql.lock().unwrap(), q3)) {
if !(0 == dc_sqlite3_execute(context, &context.sql.clone().read().unwrap(), q3)) {
(context.cb)(
context,
Event::CHAT_MODIFIED,
@@ -1943,7 +1949,7 @@ pub unsafe fn dc_set_group_explicitly_left(
if 0 == dc_is_group_explicitly_left(context, grpid) {
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"INSERT INTO leftgrps (grpid) VALUES(?);\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_text(stmt, 1i32, grpid, -1i32, None);
@@ -1957,7 +1963,7 @@ pub unsafe fn dc_is_group_explicitly_left(
) -> libc::c_int {
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT id FROM leftgrps WHERE grpid=?;\x00" as *const u8 as *const libc::c_char,
);
sqlite3_bind_text(stmt, 1i32, grpid, -1i32, None);
@@ -2000,7 +2006,7 @@ pub unsafe fn dc_set_chat_name(
new_name,
chat_id,
);
if !(0 == dc_sqlite3_execute(context, &mut context.sql.lock().unwrap(), q3)) {
if !(0 == dc_sqlite3_execute(context, &context.sql.clone().read().unwrap(), q3)) {
if dc_param_get_int((*chat).param, 'U' as i32, 0i32) == 0i32 {
(*msg).type_0 = 10i32;
(*msg).text = dc_stock_system_msg(
@@ -2141,7 +2147,7 @@ pub unsafe fn dc_forward_msgs(
as *const libc::c_char,
idsstr,
);
stmt = dc_sqlite3_prepare(context, &mut context.sql.lock().unwrap(), q3);
stmt = dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), q3);
loop {
if !(sqlite3_step(stmt) == 100i32) {
break;
@@ -2252,7 +2258,7 @@ pub unsafe extern "C" fn dc_chat_get_subtitle(mut chat: *const dc_chat_t) -> *mu
let mut r: libc::c_int = 0;
let mut stmt: *mut sqlite3_stmt =
dc_sqlite3_prepare(
(*chat).context,&mut (*chat).context.sql.lock().unwrap(),
(*chat).context,&mut (*chat).context.sql.clone().read().unwrap(),
b"SELECT c.addr FROM chats_contacts cc LEFT JOIN contacts c ON c.id=cc.contact_id WHERE cc.chat_id=?;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, (*chat).id as libc::c_int);
@@ -2283,7 +2289,7 @@ pub unsafe fn dc_get_chat_contact_cnt(
let mut ret: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT COUNT(*) FROM chats_contacts WHERE chat_id=?;\x00" as *const u8
as *const libc::c_char,
);
@@ -2368,11 +2374,11 @@ pub unsafe fn dc_chat_is_sending_locations(mut chat: *const dc_chat_t) -> libc::
pub unsafe fn dc_get_chat_cnt(mut context: &dc_context_t) -> size_t {
let mut ret: size_t = 0i32 as size_t;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(*context.sql.lock().unwrap()).cobj.is_null() {
if !(*context.sql.clone().read().unwrap()).cobj.is_null() {
/* no database, no chats - this is no error (needed eg. for information) */
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT COUNT(*) FROM chats WHERE id>9 AND blocked=0;\x00" as *const u8
as *const libc::c_char,
);
@@ -2400,7 +2406,7 @@ pub unsafe fn dc_get_chat_id_by_grpid(
stmt = dc_sqlite3_prepare(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"SELECT id, blocked, type FROM chats WHERE grpid=?;\x00" as *const u8
as *const libc::c_char,
);
@@ -2432,7 +2438,7 @@ pub unsafe fn dc_add_device_msg(
if !text.is_null() {
stmt =
dc_sqlite3_prepare(
context,&mut context.sql.lock().unwrap(),
context,&context.sql.clone().read().unwrap(),
b"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, chat_id as libc::c_int);
@@ -2450,7 +2456,7 @@ pub unsafe fn dc_add_device_msg(
if !(sqlite3_step(stmt) != 101i32) {
msg_id = dc_sqlite3_get_rowid(
context,
&mut context.sql.lock().unwrap(),
&context.sql.clone().read().unwrap(),
b"msgs\x00" as *const u8 as *const libc::c_char,
b"rfc724_mid\x00" as *const u8 as *const libc::c_char,
rfc724_mid,