diff options
author | aunsane <aunsane@gmail.com> | 2018-09-27 00:52:02 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-09-27 00:52:16 +0300 |
commit | a828455c32303c292882805388508c594a777af4 (patch) | |
tree | 74580d814a8f4e5a1544c00930ed8f2d83a560b5 /plugins | |
parent | dbdae160f14fbc36d2b2a64b7348fdbd6957935b (diff) |
dbx_sqlite:
- implementation of MetaMergeHistory/MetaSplitHistory
- fix contact delete
- enable db lock
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbcontacts.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 72 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.cpp | 18 |
3 files changed, 61 insertions, 31 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcontacts.cpp b/plugins/Dbx_sqlite/src/dbcontacts.cpp index 648de7f1a7..f181420cb4 100644 --- a/plugins/Dbx_sqlite/src/dbcontacts.cpp +++ b/plugins/Dbx_sqlite/src/dbcontacts.cpp @@ -10,7 +10,7 @@ enum { static char *ctc_stmts[SQL_CTC_STMT_NUM] = { "select count(1) from contacts limit 1;", "insert into contacts values (null);", - "delete from events where contactid = ?; delete from settings where contactid = ?; delete from contacts where id = ?;" + "delete from contacts where id = ?;" }; static sqlite3_stmt *ctc_stmts_prep[SQL_CTC_STMT_NUM] = { 0 }; diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index e03c38ebf6..d54c84b2ed 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -2,7 +2,8 @@ enum { SQL_EVT_STMT_COUNT = 0, - SQL_EVT_STMT_ADD, + SQL_EVT_STMT_ADDEVENT, + SQL_EVT_STMT_ADDCONTACTEVENT, SQL_EVT_STMT_DELETE, SQL_EVT_STMT_EDIT, SQL_EVT_STMT_BLOBSIZE, @@ -17,26 +18,31 @@ enum { SQL_EVT_STMT_FINDPREV, SQL_EVT_STMT_GETIDBYSRVID, SQL_EVT_STMT_SETSRVID, + SQL_EVT_STMT_MERGE, + SQL_EVT_STMT_SPLIT, SQL_EVT_STMT_NUM }; 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 = ?;", + "select count(1) from contact_events where contactid = ? limit 1;", + "insert into events(module, timestamp, type, flags, size, blob) values (?, ?, ?, ?, ?, ?);", + "insert into contact_events(contactid, eventid) values (?, ?);", + "delete from events where id = ?; delete from contact_events where contactid = ? and eventid = ?;", "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;", "update events set flag = ? where id = ?;", - "select contactid from events where id = ? limit 1;", - "select min(id) from events where contactid = ? limit 1;", + "select contactid from contact_events where eventid = ? limit 1;", + "select min(id) from contact_events where contactid = ? limit 1;", "select flags, id from events where contactid = ? order by id;", - "select max(id) from events where contactid = ? limit 1;", - "select id from events where contactid = ? and id > ? order by id limit 1;", - "select id from events where contactid = ? and id < ? order by id desc limit 1;", + "select max(eventid) from contact_events where contactid = ? limit 1;", + "select eventid from contact_events where contactid = ? and eventid > ? order by eventid limit 1;", + "select eventid from contact_events where contactid = ? and eventid < ? order by eventid desc limit 1;", "select id from events where module = ? and serverid = ? limit 1;", "update events set serverid = ? where id = ?;", + "insert into contact_events(contactid, eventid) select ?, eventid from contact_events where contactid = ?;", + "delete from contact_events where contactid = ? and eventid in (select eventid from contact_events where contactid = ?);", }; static sqlite3_stmt *evt_stmts_prep[SQL_EVT_STMT_NUM] = { 0 }; @@ -86,19 +92,26 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, DBEVENTINFO *dbei) MEVENT hDbEvent = 0; { mir_cslock lock(m_csDbAccess); - sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_ADD]; - sqlite3_bind_int64(stmt, 1, hContact); - sqlite3_bind_text(stmt, 2, dbei->szModule, 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, 6, dbei->cbBlob); - sqlite3_bind_blob(stmt, 7, dbei->pBlob, dbei->cbBlob, nullptr); + sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_ADDEVENT]; + 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); int rc = sqlite3_step(stmt); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 0; hDbEvent = sqlite3_last_insert_rowid(m_db); + + stmt = evt_stmts_prep[SQL_EVT_STMT_ADDCONTACTEVENT]; + sqlite3_bind_int64(stmt, 1, hContact); + sqlite3_bind_int64(stmt, 2, hDbEvent); + rc = sqlite3_step(stmt); + sqlite3_reset(stmt); + if (rc != SQLITE_DONE) + return 0; } bool neednotify = false; @@ -126,6 +139,8 @@ BOOL CDbxSQLite::DeleteEvent(MCONTACT hContact, MEVENT hDbEvent) mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_DELETE]; sqlite3_bind_int64(stmt, 1, hDbEvent); + sqlite3_bind_int64(stmt, 2, hContact); + sqlite3_bind_int64(stmt, 3, hDbEvent); int rc = sqlite3_step(stmt); sqlite3_reset(stmt); if (rc != SQLITE_DONE) @@ -419,3 +434,26 @@ BOOL CDbxSQLite::SetEventId(LPCSTR, MEVENT hDbEvent, LPCSTR szId) sqlite3_reset(stmt); return (rc != SQLITE_DONE); } + + +BOOL CDbxSQLite::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) +{ + mir_cslock lock(m_csDbAccess); + sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_MERGE]; + sqlite3_bind_int64(stmt, 1, ccMeta->contactID); + sqlite3_bind_int64(stmt, 2, ccSub->contactID); + int rc = sqlite3_step(stmt); + sqlite3_reset(stmt); + return (rc != SQLITE_DONE); +} + +BOOL CDbxSQLite::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) +{ + mir_cslock lock(m_csDbAccess); + sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_MERGE]; + sqlite3_bind_int64(stmt, 1, ccMeta->contactID); + sqlite3_bind_int64(stmt, 2, ccSub->contactID); + int rc = sqlite3_step(stmt); + sqlite3_reset(stmt); + return (rc != SQLITE_DONE); +}
\ No newline at end of file diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index 2805d10cba..f99b6b8c0f 100644 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -44,9 +44,9 @@ int CDbxSQLite::Create(const wchar_t *profile) return 1; sqlite3_exec(database, "create table contacts (id integer not null primary key);", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create table events (id integer not null primary key, contactid integer not null, module varchar(255) not null, timestamp integer not null, type integer not null, flags integer not null, size integer not null, blob any, serverid varchar(64));", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create index idx_events1 on events(id, contactid);", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create index idx_events2 on events(module, serverid);", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create table events (id integer not null primary key, module varchar(255) not null, timestamp integer not null, type integer not null, flags integer not null, size integer not null, blob any, serverid varchar(64));", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create index idx_events on events(module, serverid);", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create table contact_events (contactid integer not null, eventid integer not null, primary key(contactid, eventid)) without rowid;", nullptr, nullptr, nullptr); sqlite3_exec(database, "create table settings (contactid integer not null, module varchar(255) not null, setting varchar(255) not null, type integer not null, value any, primary key(contactid, module, setting)) without rowid;", nullptr, nullptr, nullptr); sqlite3_exec(database, "create index idx_settings on settings(contactid, module, setting);", nullptr, nullptr, nullptr); @@ -100,6 +100,8 @@ MDatabaseCommon* CDbxSQLite::Load(const wchar_t *profile, int readonly) sqlite3_exec(database, "begin transaction;", nullptr, nullptr, nullptr); sqlite3_exec(database, "pragma locking_mode = EXCLUSIVE;", nullptr, nullptr, nullptr); sqlite3_exec(database, "pragma synchronous = NORMAL;", nullptr, nullptr, nullptr); + sqlite3_exec(database, "pragma foreign_keys = OFF;", nullptr, nullptr, nullptr); + sqlite3_exec(database, "pragma journal_mode = OFF;", nullptr, nullptr, nullptr); sqlite3_exec(database, "commit;", nullptr, nullptr, nullptr); CDbxSQLite *db = new CDbxSQLite(database); @@ -144,13 +146,3 @@ BOOL CDbxSQLite::IsRelational() void CDbxSQLite::SetCacheSafetyMode(BOOL) { } - -BOOL CDbxSQLite::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) -{ - return 0; -} - -BOOL CDbxSQLite::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) -{ - return 0; -} |