example of how to prepare now

This commit is contained in:
dignifiedquire
2019-07-06 13:36:06 +02:00
parent 078c8859f4
commit 813aae08a3
2 changed files with 22 additions and 28 deletions

View File

@@ -671,29 +671,33 @@ pub unsafe fn dc_get_version_str() -> *mut libc::c_char {
pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t {
let show_deaddrop = 0;
let ret = unsafe { dc_array_new(128 as size_t) };
if !ret.is_null() {
if let Some(ref mut stmt) = dc_sqlite3_prepare(
context,
&context.sql,
if ret.is_null() {
return ret;
}
let conn_lock = context.sql.get_conn();
if let Some(ref mut stmt) = conn_lock.as_ref().and_then(|conn| {
conn.prepare(
"SELECT m.id FROM msgs m LEFT JOIN contacts ct \
ON m.from_id=ct.id LEFT JOIN chats c ON m.chat_id=c.id WHERE m.state=? \
AND m.hidden=0 \
AND m.chat_id>? \
AND ct.blocked=0 \
AND (c.blocked=0 OR c.blocked=?) ORDER BY m.timestamp DESC,m.id DESC;",
) {
match stmt.query_map(&[10, 9, if 0 != show_deaddrop { 2 } else { 0 }], |row| {
row.get(0)
}) {
Ok(rows) => {
for row in rows {
if let Ok(id) = row {
unsafe { dc_array_add_id(ret, id) };
}
)
.ok()
}) {
match stmt.query_map(&[10, 9, if 0 != show_deaddrop { 2 } else { 0 }], |row| {
row.get(0)
}) {
Ok(rows) => {
for row in rows {
if let Ok(id) = row {
unsafe { dc_array_add_id(ret, id) };
}
}
Err(_err) => {}
}
Err(_err) => {}
}
}

View File

@@ -55,13 +55,8 @@ impl SQLite {
}
}
pub fn prepare(&self, sql: &str) -> rusqlite::Result<Statement> {
// TODO: switch to direct execution
unimplemented!()
// match &*self.connection.read().unwrap() {
// Some(ref conn) => conn.prepare(sql),
// None => panic!("Querying closed SQLite database"),
// }
pub fn get_conn(&self) -> std::sync::RwLockReadGuard<Option<Connection>> {
self.connection.read().unwrap()
}
pub fn query_row<T, P, F>(&self, sql: &str, params: P, f: F) -> rusqlite::Result<T>
@@ -866,13 +861,8 @@ pub fn dc_sqlite3_prepare<'a>(
sql: &'a SQLite,
querystr: &'a str,
) -> Option<Statement<'a>> {
match sql.prepare(querystr) {
Ok(s) => Some(s),
Err(err) => {
error!(context, 0, "Query failed: {} ({})", querystr, err);
None
}
}
// TODO: remove once it is not used anymore
unimplemented!()
}
pub fn dc_sqlite3_is_open(sql: &SQLite) -> libc::c_int {