diff options
author | aunsane <aunsane@gmail.com> | 2018-09-23 21:11:53 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-09-27 00:52:16 +0300 |
commit | dbdae160f14fbc36d2b2a64b7348fdbd6957935b (patch) | |
tree | d9b1cb3de72e81d88a10a832a76891a11be0f43b /plugins | |
parent | 7eabf1f5a4d7691af4cbf7ac470b4aca75f78443 (diff) |
dbx_sqlite: edit event implementation
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 29 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.h | 1 |
3 files changed, 30 insertions, 2 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index 22324d96e1..e03c38ebf6 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -4,6 +4,7 @@ enum { SQL_EVT_STMT_COUNT = 0, SQL_EVT_STMT_ADD, SQL_EVT_STMT_DELETE, + SQL_EVT_STMT_EDIT, SQL_EVT_STMT_BLOBSIZE, SQL_EVT_STMT_GET, SQL_EVT_STMT_GETFLAGS, @@ -23,6 +24,7 @@ static char *evt_stmts[SQL_EVT_STMT_NUM] = { "select count(1) from events where contactid = ? limit 1;", "insert into events(contactid, module, timestamp, type, flags, size, blob) values (?, ?, ?, ?, ?, ?, ?);", "delete from events where id = ?;", + "update events set module = ?, timestamp = ?, type = ?, flags = ?, size = ?, blob = ? where id = ?;", "select size from events where id = ? limit 1;", "select module, timestamp, type, flags, size, blob from events where id = ? limit 1;", "select flags from events where id = ? limit 1;", @@ -135,9 +137,32 @@ BOOL CDbxSQLite::DeleteEvent(MCONTACT hContact, MEVENT hDbEvent) return 0; } -BOOL CDbxSQLite::EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbe) +BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, DBEVENTINFO *dbei) { - return 1; // not supported + if (dbei == nullptr) + return 1; + + if (dbei->timestamp == 0) + return 1; + + DBCachedContact *cc = m_cache->GetCachedContact(hContact); + if (cc == nullptr) + return 1; + + mir_cslock lock(m_csDbAccess); + sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_EDIT]; + sqlite3_bind_text(stmt, 1, dbei->szModule, mir_strlen(dbei->szModule), nullptr); + sqlite3_bind_int64(stmt, 2, dbei->timestamp); + sqlite3_bind_int(stmt, 3, dbei->eventType); + sqlite3_bind_int64(stmt, 4, dbei->flags); + sqlite3_bind_int64(stmt, 5, dbei->cbBlob); + sqlite3_bind_blob(stmt, 6, dbei->pBlob, dbei->cbBlob, nullptr); + sqlite3_bind_int64(stmt, 7, hDbEvent); + int rc = sqlite3_step(stmt); + if (rc == SQLITE_DONE) + NotifyEventHooks(hEventEditedEvent, hContact, (LPARAM)hDbEvent); + sqlite3_reset(stmt); + return (rc != SQLITE_DONE); } LONG CDbxSQLite::GetBlobSize(MEVENT hDbEvent) diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index 8b73517791..2805d10cba 100644 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -6,6 +6,7 @@ CDbxSQLite::CDbxSQLite(sqlite3 *database) hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED); hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED); hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED); + hEventEditedEvent = CreateHookableEvent(ME_DB_EVENT_EDITED); hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED); hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD); hEventMarkedRead = CreateHookableEvent(ME_DB_EVENT_MARKED_READ); @@ -17,6 +18,7 @@ CDbxSQLite::~CDbxSQLite() DestroyHookableEvent(hContactAddedEvent); DestroyHookableEvent(hContactDeletedEvent); DestroyHookableEvent(hEventAddedEvent); + DestroyHookableEvent(hEventEditedEvent); DestroyHookableEvent(hEventDeletedEvent); DestroyHookableEvent(hEventFilterAddedEvent); DestroyHookableEvent(hEventMarkedRead); diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index 08e3e419f2..190745d41f 100644 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -8,6 +8,7 @@ private: HANDLE hContactAddedEvent; HANDLE hContactDeletedEvent; HANDLE hEventAddedEvent; + HANDLE hEventEditedEvent; HANDLE hEventDeletedEvent; HANDLE hEventFilterAddedEvent; HANDLE hEventMarkedRead; |