From 75cff2d80be9ea6c5b946fbe59ef8bc56919f04d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 12 Mar 2015 22:16:37 +0000 Subject: support for meta merge/split in LMDB git-svn-id: http://svn.miranda-ng.org/main/trunk@12390 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dbx_mdb/src/dbcontacts.cpp | 47 +++++++++++++++++++++++++++++++------- plugins/Dbx_mdb/src/dbsettings.cpp | 2 +- 2 files changed, 40 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 6a3c4dca44..958f48676a 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -152,23 +152,54 @@ BOOL CDbxMdb::MetaSetDefault(DBCachedContact *cc) return db_set_dw(cc->contactID, META_PROTO, "Default", cc->nDefault); } -static int SortEvent(const DBEvent *p1, const DBEvent *p2) -{ - return (LONG)p1->timestamp - (LONG)p2->timestamp; -} +///////////////////////////////////////////////////////////////////////////////////////// BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) { - mir_cslock lck(m_csDbAccess); - return -11; + DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, insVal = { 0, 0, ccMeta->contactID }; + MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(insVal), &insVal }, data; + + txn_ptr trnlck(m_pMdbEnv); + + cursor_ptr cursor(trnlck, m_dbEventsSort); + mdb_cursor_get(cursor, &key, &data, MDB_SET); + while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) { + DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data; + if (pKey->dwContactId != ccSub->contactID) + break; + + insVal.ts = pKey->ts; + insVal.dwEventId = pKey->dwEventId; + mdb_put(trnlck, m_dbEventsSort, &key2, &data, 0); + } + + trnlck.commit(); + return 0; } ///////////////////////////////////////////////////////////////////////////////////////// BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) { - mir_cslock lck(m_csDbAccess); - return -11; + DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, delVal = { 0, 0, ccMeta->contactID }; + MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(delVal), &delVal }, data; + + txn_ptr trnlck(m_pMdbEnv); + + cursor_ptr cursor(trnlck, m_dbEventsSort); + mdb_cursor_get(cursor, &key, &data, MDB_SET); + while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) { + DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data; + if (pKey->dwContactId != ccSub->contactID) + break; + + delVal.ts = pKey->ts; + delVal.dwEventId = pKey->dwEventId; + mdb_del(trnlck, m_dbEventsSort, &key2, &data); + } + + trnlck.commit(); + return 0; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp index f9516e4a99..1d0a69bc0b 100644 --- a/plugins/Dbx_mdb/src/dbsettings.cpp +++ b/plugins/Dbx_mdb/src/dbsettings.cpp @@ -283,7 +283,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::GetContactSettingStr(MCONTACT contactID, LPCSTR szM if (iSaveType == DBVT_WCHAR) { if (dbv->type != DBVT_UTF8) { int len = MultiByteToWideChar(CP_ACP, 0, dbv->pszVal, -1, NULL, 0); - wchar_t* wszResult = (wchar_t*)mir_alloc((len + 1)*sizeof(wchar_t)); + wchar_t *wszResult = (wchar_t*)mir_alloc((len + 1)*sizeof(wchar_t)); if (wszResult == NULL) return 1; -- cgit v1.2.3