diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-16 18:35:26 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-16 18:35:26 +0000 |
commit | cf0b0b736cea27c86850a8b3485bc200bddb35ca (patch) | |
tree | fa4d5a24df04bc5e2aacb438f1d6b0d5e616715b /plugins/Dbx_mdb | |
parent | 0cf6c3523f81dc179363b6184175573640f7554c (diff) |
dbx_lmdb: crutches removed; crash fix (?)
git-svn-id: http://svn.miranda-ng.org/main/trunk@16488 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 26 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.cpp | 8 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbsettings.cpp | 6 |
3 files changed, 23 insertions, 17 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index f19811b10e..442e499d04 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -155,7 +155,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact() DWORD dwContactId;
{
mir_cslock lck(m_csDbAccess);
- dwContactId = m_dwMaxContactId++;
+ dwContactId = ++m_dwMaxContactId;
DBCachedContact *cc = m_cache->AddContactToCache(dwContactId);
cc->dbc.dwSignature = DBCONTACT_SIGNATURE;
@@ -205,14 +205,16 @@ void CDbxMdb::GatherContactHistory(MCONTACT hContact, LIST<EventItem> &list) txn_ptr_ro trnlck(m_txn);
cursor_ptr_ro cursor(m_curEventsSort);
- mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE);
- do {
- const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
- if (pKey->dwContactId != hContact)
- return;
-
- list.insert(new EventItem(pKey->ts, pKey->dwEventId));
- } while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
+ if (mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE) == MDB_SUCCESS)
+ {
+ do {
+ const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
+ if (pKey->dwContactId != hContact)
+ return;
+
+ list.insert(new EventItem(pKey->ts, pKey->dwEventId));
+ } while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
+ }
}
BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
@@ -223,7 +225,8 @@ BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) for (int i = 0; i < list.getCount(); i++) {
EventItem *EI = list[i];
- for (;; Remap()) {
+ for (;; Remap())
+ {
txn_ptr trnlck(m_pMdbEnv);
DBEventSortingKey insVal = { EI->eventId, EI->ts, ccMeta->contactID };
MDB_val key = { sizeof(insVal), &insVal }, data = { 1, "" };
@@ -341,11 +344,8 @@ void CDbxMdb::FillContacts() DBCachedContact *cc = arContacts[i];
CheckProto(cc, "");
- m_dwMaxContactId = max(m_dwMaxContactId, cc->contactID+1);
m_contactCount++;
- m_dwMaxEventId = max(m_dwMaxEventId, FindLastEvent(cc->contactID) + 1);
-
DBVARIANT dbv; dbv.type = DBVT_DWORD;
cc->nSubs = (0 != GetContactSetting(cc->contactID, META_PROTO, "NumContacts", &dbv)) ? -1 : dbv.dVal;
if (cc->nSubs != -1) {
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index 57374de534..521a317b79 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -121,13 +121,21 @@ int CDbxMdb::Load(bool bSkipInit) trnlck.commit();
{
+ MDB_val key, val;
+
mdb_txn_begin(m_pMdbEnv, nullptr, MDB_RDONLY, &m_txn);
mdb_cursor_open(m_txn, m_dbEvents, &m_curEvents);
+ mdb_cursor_get(m_curEvents, &key, &val, MDB_LAST);
+ m_dwMaxEventId = *(MEVENT*)key.mv_data + 1;
+
mdb_cursor_open(m_txn, m_dbEventsSort, &m_curEventsSort);
mdb_cursor_open(m_txn, m_dbSettings, &m_curSettings);
mdb_cursor_open(m_txn, m_dbModules, &m_curModules);
+
mdb_cursor_open(m_txn, m_dbContacts, &m_curContacts);
+ mdb_cursor_get(m_curContacts, &key, &val, MDB_LAST);
+ m_dwMaxContactId = *(DWORD*)key.mv_data + 1;
mdb_txn_reset(m_txn);
}
diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp index 623bea9024..6ea4d009cb 100644 --- a/plugins/Dbx_mdb/src/dbsettings.cpp +++ b/plugins/Dbx_mdb/src/dbsettings.cpp @@ -562,7 +562,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumContactSettings(MCONTACT contactID, DBCONTACTEN if (!dbces->szModule)
return -1;
- int result = 0;
+ int result = -1;
DBSettingKey keySearch;
keySearch.dwContactID = contactID;
@@ -577,17 +577,15 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumContactSettings(MCONTACT contactID, DBCONTACTEN if (mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE) == MDB_SUCCESS)
{
- size_t i = 0;
do
{
const DBSettingKey *pKey = (const DBSettingKey*)key.mv_data;
if (pKey->dwContactID != contactID || pKey->dwOfsModule != keySearch.dwOfsModule)
- return i == 0 ? -1 : result;
+ return result;
char szSetting[256];
strncpy_s(szSetting, pKey->szSettingName, key.mv_size - sizeof(DWORD) * 2);
result = (dbces->pfnEnumProc)(szSetting, dbces->lParam);
- i++;
}
while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
}
|