From e215b9e602c3a3e4dd9ee2b9f9d1bb6bad9e4060 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 4 Aug 2023 17:18:17 +0300 Subject: if db_event_edit is called without a blob, there's no need to rewrite it --- plugins/Dbx_sqlite/src/dbevents.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'plugins/Dbx_sqlite/src/dbevents.cpp') diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index 73baf8389c..1206b30b09 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -254,7 +254,7 @@ BOOL CDbxSQLite::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei) DBEVENTINFO tmp = *dbei; mir_ptr pCryptBlob; - if (m_bEncrypted) { + if (m_bEncrypted && tmp.pBlob) { size_t len; uint8_t *pResult = m_crypto->encodeBuffer(tmp.pBlob, tmp.cbBlob, &len); if (pResult != nullptr) { @@ -265,14 +265,21 @@ BOOL CDbxSQLite::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei) } mir_cslockfull lock(m_csDbAccess); - sqlite3_stmt *stmt = InitQuery("UPDATE events SET module = ?, timestamp = ?, type = ?, flags = ?, data = ?, is_read = ? WHERE id = ?;", qEvEdit); - sqlite3_bind_text(stmt, 1, tmp.szModule, (int)mir_strlen(tmp.szModule), nullptr); - sqlite3_bind_int64(stmt, 2, tmp.timestamp); - sqlite3_bind_int(stmt, 3, tmp.eventType); - sqlite3_bind_int64(stmt, 4, tmp.flags); - sqlite3_bind_blob(stmt, 5, tmp.pBlob, tmp.cbBlob, nullptr); - sqlite3_bind_int(stmt, 6, tmp.markedRead()); - sqlite3_bind_int64(stmt, 7, hDbEvent); + sqlite3_stmt *stmt; + if (tmp.pBlob) + stmt = InitQuery("UPDATE events SET module = ?, timestamp = ?, type = ?, flags = ?, data = ?, is_read = ? WHERE id = ?;", qEvEdit1); + else + stmt = InitQuery("UPDATE events SET module = ?, timestamp = ?, type = ?, flags = ?, is_read = ? WHERE id = ?;", qEvEdit2); + + int i = 1; + sqlite3_bind_text(stmt, i++, tmp.szModule, (int)mir_strlen(tmp.szModule), nullptr); + sqlite3_bind_int64(stmt, i++, tmp.timestamp); + sqlite3_bind_int(stmt, i++, tmp.eventType); + sqlite3_bind_int64(stmt, i++, tmp.flags); + if (tmp.pBlob) + sqlite3_bind_blob(stmt, i++, tmp.pBlob, tmp.cbBlob, nullptr); + sqlite3_bind_int(stmt, i++, tmp.markedRead()); + sqlite3_bind_int64(stmt, i++, hDbEvent); int rc = sqlite3_step(stmt); logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); -- cgit v1.2.3