diff options
author | George Hazan <george.hazan@gmail.com> | 2015-01-14 14:29:52 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-01-14 14:29:52 +0000 |
commit | e37f12dec252a78cdf94d31ccc87ce37c1436a1f (patch) | |
tree | 09d50f93a1f260e054908c775264819e82a0db48 /plugins/Dbx_mdb/src/dbcontacts.cpp | |
parent | 5f4a6f00c20468e6adc3a7bf691eccef55d2324c (diff) |
txn_ptr & cursor_ptr classes
git-svn-id: http://svn.miranda-ng.org/main/trunk@11853 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src/dbcontacts.cpp')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 0a6e6859f1..48c8b7e7cb 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -87,14 +87,14 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID) // delete
mir_cslock lck(m_csDbAccess);
- MDB_val key = { sizeof(DWORD), &contactID }; + MDB_val key = { sizeof(DWORD), &contactID };
for (;; Remap()) {
- txn_lock trnlck(m_pMdbEnv); - mdb_del(trnlck, m_dbContacts, &key, NULL); - if (trnlck.commit()) - break; - } + txn_ptr trnlck(m_pMdbEnv);
+ mdb_del(trnlck, m_dbContacts, &key, NULL);
+ if (trnlck.commit())
+ break;
+ }
return 0;
}
@@ -107,17 +107,17 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact() dbc.eventCount = 0;
{
mir_cslock lck(m_csDbAccess);
- dwContactId = m_dwMaxContactId++; - - MDB_val key = { sizeof(DWORD), &dwContactId }; - MDB_val data = { sizeof(DBContact), &dbc }; - + dwContactId = m_dwMaxContactId++;
+
+ MDB_val key = { sizeof(DWORD), &dwContactId };
+ MDB_val data = { sizeof(DBContact), &dbc };
+
for (;; Remap()) {
- txn_lock trnlck(m_pMdbEnv); - mdb_put(trnlck, m_dbContacts, &key, &data, 0); - if (trnlck.commit()) - break; - } + txn_ptr trnlck(m_pMdbEnv);
+ mdb_put(trnlck, m_dbContacts, &key, &data, 0);
+ if (trnlck.commit())
+ break;
+ }
DBCachedContact *cc = m_cache->AddContactToCache(dwContactId);
cc->dwDriverData = 0;
@@ -173,19 +173,18 @@ void CDbxMdb::FillContacts() {
m_contactCount = 0;
- txn_lock trnlck(m_pMdbEnv); - mdb_open(trnlck, "contacts", MDB_INTEGERKEY, &m_dbContacts); + txn_ptr trnlck(m_pMdbEnv);
+ mdb_open(trnlck, "contacts", MDB_INTEGERKEY, &m_dbContacts);
+
+ cursor_ptr cursor(trnlck, m_dbContacts);
- MDB_cursor *cursor; - mdb_cursor_open(trnlck, m_dbContacts, &cursor); - - MDB_val key, data; + MDB_val key, data;
while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) {
DBContact *dbc = (DBContact*)data.mv_data;
if (dbc->signature != DBCONTACT_SIGNATURE)
DatabaseCorruption(NULL);
- DWORD dwContactId = *(DWORD*)key.mv_data; + DWORD dwContactId = *(DWORD*)key.mv_data;
DBCachedContact *cc = m_cache->AddContactToCache(dwContactId);
cc->dwDriverData = 0;
CheckProto(cc, "");
@@ -206,6 +205,4 @@ void CDbxMdb::FillContacts() cc->nDefault = (0 != GetContactSetting(dwContactId, META_PROTO, "Default", &dbv)) ? -1 : dbv.dVal;
cc->parentID = (0 != GetContactSetting(dwContactId, META_PROTO, "ParentMeta", &dbv)) ? NULL : dbv.dVal;
}
-
- mdb_cursor_close(cursor);
}
|