summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-03-10 16:26:57 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-03-10 16:26:57 +0000
commitcd72e104e05f62a62f034cebf10c2b171bece2c8 (patch)
tree66c7269e96d5f3f4d7dc4ff6c0307891deaa4a79 /plugins/Dbx_mdb
parent3739d103d4369a36749f5ef4884bf470f8ccf26e (diff)
fix for correct transaction processing
git-svn-id: http://svn.miranda-ng.org/main/trunk@12375 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb')
-rw-r--r--plugins/Dbx_mdb/src/commonheaders.h6
-rw-r--r--plugins/Dbx_mdb/src/dbcontacts.cpp4
-rw-r--r--plugins/Dbx_mdb/src/dbevents.cpp18
-rw-r--r--plugins/Dbx_mdb/src/dbmodulechain.cpp2
-rw-r--r--plugins/Dbx_mdb/src/dbsettings.cpp3
5 files changed, 18 insertions, 15 deletions
diff --git a/plugins/Dbx_mdb/src/commonheaders.h b/plugins/Dbx_mdb/src/commonheaders.h
index 2d1a6ae580..e68a261e56 100644
--- a/plugins/Dbx_mdb/src/commonheaders.h
+++ b/plugins/Dbx_mdb/src/commonheaders.h
@@ -100,6 +100,12 @@ public:
__forceinline operator MDB_cursor*() const { return m_cursor; }
};
+#define MDB_CHECK(A,B) \
+ switch(A) { \
+ case MDB_SUCCESS: break; \
+ case MDB_MAP_FULL: continue; \
+ default: return (B); }
+
#include "dbintf.h"
#include "resource.h"
#include "version.h"
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp
index 094cb0331e..6a3c4dca44 100644
--- a/plugins/Dbx_mdb/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdb/src/dbcontacts.cpp
@@ -100,7 +100,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID)
for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
- mdb_del(trnlck, m_dbContacts, &key, NULL);
+ MDB_CHECK(mdb_del(trnlck, m_dbContacts, &key, NULL), 0);
if (trnlck.commit())
break;
}
@@ -122,7 +122,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact()
for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
- mdb_put(trnlck, m_dbContacts, &key, &data, 0);
+ MDB_CHECK(mdb_put(trnlck, m_dbContacts, &key, &data, 0), 0);
if (trnlck.commit())
break;
}
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp
index 96423dbc33..c896049e76 100644
--- a/plugins/Dbx_mdb/src/dbevents.cpp
+++ b/plugins/Dbx_mdb/src/dbevents.cpp
@@ -77,12 +77,11 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
mir_cslockfull lck(m_csDbAccess);
DWORD dwEventId = ++m_dwMaxEventId;
- txn_ptr txn(m_pMdbEnv);
-
for (;; Remap()) {
+ txn_ptr txn(m_pMdbEnv);
+
MDB_val key = { sizeof(int), &dwEventId }, data = { sizeof(DBEvent) + dbe.cbBlob, NULL };
- if (mdb_put(txn, m_dbEvents, &key, &data, MDB_RESERVE) != MDB_SUCCESS)
- return 0;
+ MDB_CHECK(mdb_put(txn, m_dbEvents, &key, &data, MDB_RESERVE), 0);
BYTE *pDest = (BYTE*)data.mv_data;
memcpy(pDest, &dbe, sizeof(DBEvent));
@@ -92,22 +91,21 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
DBEventSortingKey key2 = { contactID, dbe.timestamp, dwEventId };
key.mv_size = sizeof(key2); key.mv_data = &key2;
data.mv_size = 1; data.mv_data = "";
- if (mdb_put(txn, m_dbEventsSort, &key, &data, 0) != MDB_SUCCESS)
- return 0;
+ MDB_CHECK(mdb_put(txn, m_dbEventsSort, &key, &data, 0), 0);
cc->Advance(dwEventId, dbe);
MDB_val keyc = { sizeof(int), &contactID }, datac = { sizeof(DBContact), &cc->dbc };
- mdb_put(txn, m_dbContacts, &keyc, &datac, 0);
+ MDB_CHECK(mdb_put(txn, m_dbContacts, &keyc, &datac, 0), 0);
// insert an event into a sub's history too
if (ccSub != NULL) {
key2.dwContactId = ccSub->contactID;
- mdb_put(txn, m_dbEventsSort, &key, &data, 0);
+ MDB_CHECK(mdb_put(txn, m_dbEventsSort, &key, &data, 0), 0);
ccSub->Advance(dwEventId, dbe);
datac.mv_data = &ccSub->dbc;
keyc.mv_data = &ccSub->contactID;
- mdb_put(txn, m_dbContacts, &keyc, &datac, 0);
+ MDB_CHECK(mdb_put(txn, m_dbContacts, &keyc, &datac, 0), 0);
}
if (txn.commit())
@@ -386,7 +384,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent
/////////////////////////////////////////////////////////////////////////////////////////
// low-level history cleaner
-int CDbxMdb::WipeContactHistory(DBContact *dbc)
+int CDbxMdb::WipeContactHistory(DBContact*)
{
// drop subContact's history if any
return 0;
diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp
index a42ab0b221..9342ea3cb1 100644
--- a/plugins/Dbx_mdb/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp
@@ -103,7 +103,7 @@ DWORD CDbxMdb::GetModuleNameOfs(const char *szName)
for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
mdb_open(trnlck, "modules", MDB_INTEGERKEY, &m_dbModules);
- mdb_put(trnlck, m_dbModules, &key, &data, 0);
+ MDB_CHECK(mdb_put(trnlck, m_dbModules, &key, &data, 0), -1);
if (trnlck.commit())
break;
}
diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp
index 2955466c50..99c6d006db 100644
--- a/plugins/Dbx_mdb/src/dbsettings.cpp
+++ b/plugins/Dbx_mdb/src/dbsettings.cpp
@@ -494,8 +494,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::WriteContactSetting(MCONTACT contactID, DBCONTACTWR
for (;; Remap()) {
txn_ptr trnlck(m_pMdbEnv);
- if (mdb_put(trnlck, m_dbSettings, &key, &data, MDB_RESERVE) != 0)
- return 1;
+ MDB_CHECK(mdb_put(trnlck, m_dbSettings, &key, &data, MDB_RESERVE), 1);
BYTE *pBlob = (BYTE*)data.mv_data;
*pBlob++ = dbcwWork.value.type;