text stringlengths 0 357 |
|---|
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT COUNT(*) FROM msgs WHERE rfc724_mid=?;"); |
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
ret = sqlite3_column_int(stmt, 0); |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
/** |
* Check, if the given Message-ID exists in the database. |
* If not, the caller loads the message typically completely from the server and parses it. |
* To avoid unnecessary dowonloads and parsing, we should even keep unuseful messages |
* in the database (we can leave the other fields empty to save space). |
* |
* @private @memberof dc_context_t |
*/ |
uint32_t dc_rfc724_mid_exists(dc_context_t* context, const char* rfc724_mid, char** ret_server_folder, uint32_t* ret_server_uid) |
{ |
uint32_t ret = 0; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || rfc724_mid==NULL || rfc724_mid[0]==0) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT server_folder, server_uid, id FROM msgs WHERE rfc724_mid=?;"); |
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
if (ret_server_folder) { *ret_server_folder = NULL; } |
if (ret_server_uid) { *ret_server_uid = 0; } |
goto cleanup; |
} |
if (ret_server_folder) { *ret_server_folder = dc_strdup((char*)sqlite3_column_text(stmt, 0)); } |
if (ret_server_uid) { *ret_server_uid = sqlite3_column_int(stmt, 1); /* may be 0 */ } |
ret = sqlite3_column_int(stmt, 2); |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
void dc_update_server_uid(dc_context_t* context, const char* rfc724_mid, const char* server_folder, uint32_t server_uid) |
{ |
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, |
"UPDATE msgs SET server_folder=?, server_uid=? WHERE rfc724_mid=?;"); /* we update by "rfc724_mid" instead of "id" as there may be several db-entries refering to the same "rfc724_mid" */ |
sqlite3_bind_text(stmt, 1, server_folder, -1, SQLITE_STATIC); |
sqlite3_bind_int (stmt, 2, server_uid); |
sqlite3_bind_text(stmt, 3, rfc724_mid, -1, SQLITE_STATIC); |
sqlite3_step(stmt); |
sqlite3_finalize(stmt); |
} |
/** |
* Get a single message object of the type dc_msg_t. |
* For a list of messages in a chat, see dc_get_chat_msgs() |
* For a list or chats, see dc_get_chatlist() |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param msg_id The message ID for which the message object should be created. |
* @return A dc_msg_t message object. |
* On errors, NULL is returned. |
* When done, the object must be freed using dc_msg_unref(). |
*/ |
dc_msg_t* dc_get_msg(dc_context_t* context, uint32_t msg_id) |
{ |
int success = 0; |
dc_msg_t* obj = dc_msg_new_untyped(context); |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
if (!dc_msg_load_from_db(obj, context, msg_id)) { |
goto cleanup; |
} |
success = 1; |
cleanup: |
if (success) { |
return obj; |
} |
else { |
dc_msg_unref(obj); |
return NULL; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.