summaryrefslogtreecommitdiff
path: root/plugins/Dbx_sqlite/src/dbevents.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-06-15 18:35:21 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-06-15 18:35:28 +0300
commit436e303e24e5046d6cc52ac3da51a0b51adbef36 (patch)
tree4f7d3b27ad24e710dae845558e2d719b54d1d88a /plugins/Dbx_sqlite/src/dbevents.cpp
parentf0d86d413859d402331b49b98db7d61fef801489 (diff)
simpler way of applying server ids to messages
Diffstat (limited to 'plugins/Dbx_sqlite/src/dbevents.cpp')
-rwxr-xr-xplugins/Dbx_sqlite/src/dbevents.cpp36
1 files changed, 14 insertions, 22 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index 9c24ddb3f0..4b5c3e80de 100755
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -14,7 +14,6 @@ enum {
SQL_EVT_STMT_FINDFIRSTUNREAD,
SQL_EVT_STMT_FINDLAST,
SQL_EVT_STMT_GETIDBYSRVID,
- SQL_EVT_STMT_SETSRVID,
SQL_EVT_STMT_ADDEVENT_SRT,
SQL_EVT_STMT_DELETE_SRT,
SQL_EVT_STMT_META_SPLIT,
@@ -37,7 +36,7 @@ static const char* reverse_order_pos_query =
static const char *evt_stmts[SQL_EVT_STMT_NUM] = {
"select count(1) from events where contact_id = ? limit 1;",
- "insert into events(contact_id, module, timestamp, type, flags, data) values (?, ?, ?, ?, ?, ?);",
+ "insert into events(contact_id, module, timestamp, type, flags, data, server_id) values (?, ?, ?, ?, ?, ?, ?);",
"delete from events where id = ?;",
"update events set module = ?, timestamp = ?, type = ?, flags = ?, blob = ? where id = ?;",
"select length(data) from events where id = ? limit 1;",
@@ -49,7 +48,6 @@ static const char *evt_stmts[SQL_EVT_STMT_NUM] = {
"select id, timestamp from events where contact_id = ? and (flags & ?) = 0 order by timestamp, id limit 1;",
reverse_order_query,
"select id, timestamp from events where module = ? and server_id = ? limit 1;",
- "update events set server_id = ? where id = ?;",
"insert into events_srt(id, contact_id, timestamp) values (?, ?, ?);",
"delete from events_srt where id = ?;",
"delete from events_srt where contact_id = ?;",
@@ -173,14 +171,23 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei)
MEVENT hDbEvent = 0;
{
+ const char *szEventId;
+ DWORD dwFlags = dbei->flags;
+ if (dbei->szId != nullptr) {
+ dwFlags |= DBEF_HAS_ID;
+ szEventId = dbei->szId;
+ }
+ else szEventId = "";
+
mir_cslock lock(m_csDbAccess);
sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_ADDEVENT];
sqlite3_bind_int64(stmt, 1, hContact);
sqlite3_bind_text(stmt, 2, dbei->szModule, (int)mir_strlen(dbei->szModule), nullptr);
sqlite3_bind_int64(stmt, 3, dbei->timestamp);
sqlite3_bind_int(stmt, 4, dbei->eventType);
- sqlite3_bind_int64(stmt, 5, dbei->flags);
+ sqlite3_bind_int64(stmt, 5, dwFlags);
sqlite3_bind_blob(stmt, 6, dbei->pBlob, dbei->cbBlob, nullptr);
+ sqlite3_bind_text(stmt, 7, szEventId, (int)mir_strlen(szEventId), nullptr);
int rc = sqlite3_step(stmt);
assert(rc == SQLITE_DONE);
sqlite3_reset(stmt);
@@ -209,7 +216,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei)
ccSub->AddEvent(hDbEvent, dbei->timestamp, !dbei->markedRead());
}
- char *module = m_modules.find(dbei->szModule);
+ char *module = m_modules.find((char*)dbei->szModule);
if (module == nullptr)
m_modules.insert(mir_strdup(dbei->szModule));
}
@@ -289,7 +296,7 @@ BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO
if (cc->IsSub() && (cc = m_cache->GetCachedContact(cc->parentID)))
cc->EditEvent(hDbEvent, dbei->timestamp, !dbei->markedRead());
- char *module = m_modules.find(dbei->szModule);
+ char *module = m_modules.find((char*)dbei->szModule);
if (module == nullptr)
m_modules.insert(mir_strdup(dbei->szModule));
}
@@ -619,7 +626,7 @@ MEVENT CDbxSQLite::FindPrevEvent(MCONTACT hContact, MEVENT hDbEvent)
return 0;
}
- while (hDbEvent != sqlite3_column_int64(evt_cur_backwd, 0))
+ while (hDbEvent != sqlite3_column_int64(evt_cur_backwd, 0))
{
int rc = sqlite3_step(evt_cur_backwd);
assert(rc == SQLITE_ROW || rc == SQLITE_DONE);
@@ -669,21 +676,6 @@ MEVENT CDbxSQLite::GetEventById(LPCSTR szModule, LPCSTR szId)
return hDbEvent;
}
-BOOL CDbxSQLite::SetEventId(LPCSTR, MEVENT hDbEvent, LPCSTR szId)
-{
- if (hDbEvent == 0 || szId == nullptr)
- return 1;
-
- mir_cslock lock(m_csDbAccess);
- sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_SETSRVID];
- sqlite3_bind_text(stmt, 1, szId, (int)mir_strlen(szId), nullptr);
- sqlite3_bind_int64(stmt, 2, hDbEvent);
- int rc = sqlite3_step(stmt);
- assert(rc == SQLITE_ROW || rc == SQLITE_DONE);
- sqlite3_reset(stmt);
- return (rc != SQLITE_DONE);
-}
-
BOOL CDbxSQLite::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
{
//TODO: test this