diff options
author | aunsane <aunsane@gmail.com> | 2018-09-23 16:29:02 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-09-23 16:29:02 +0300 |
commit | 6e085b274205448082c43f1669d7dfed1ff75dfe (patch) | |
tree | dca2395ceffa428a5886a5251d9b36bfb5d8b18c /plugins | |
parent | 89a3160416316af2ff0b8de9b247583a4ac103f8 (diff) |
dbx_sqlite: more fixes
- contacts: correct loading of mc's into cache
- events: fix queries
- codrrect deinit of sql statements
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbcontacts.cpp | 13 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 25 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.cpp | 8 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/stdafx.h | 1 |
4 files changed, 36 insertions, 11 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcontacts.cpp b/plugins/Dbx_sqlite/src/dbcontacts.cpp index ce9af1ddc4..648de7f1a7 100644 --- a/plugins/Dbx_sqlite/src/dbcontacts.cpp +++ b/plugins/Dbx_sqlite/src/dbcontacts.cpp @@ -28,6 +28,19 @@ void CDbxSQLite::InitContacts() while (sqlite3_step(stmt) == SQLITE_ROW) { MCONTACT hContact = sqlite3_column_int64(stmt, 0); DBCachedContact *cc = m_cache->AddContactToCache(hContact); + + DBVARIANT dbv = { DBVT_DWORD }; + cc->nSubs = (0 != GetContactSetting(cc->contactID, META_PROTO, "NumContacts", &dbv)) ? -1 : dbv.dVal; + if (cc->nSubs != -1) { + cc->pSubs = (MCONTACT*)mir_alloc(cc->nSubs * sizeof(MCONTACT)); + for (int k = 0; k < cc->nSubs; k++) { + char setting[100]; + mir_snprintf(setting, _countof(setting), "Handle%d", k); + cc->pSubs[k] = (0 != GetContactSetting(cc->contactID, META_PROTO, setting, &dbv)) ? 0 : dbv.dVal; + } + } + cc->nDefault = (0 != GetContactSetting(cc->contactID, META_PROTO, "Default", &dbv)) ? -1 : dbv.dVal; + cc->parentID = (0 != GetContactSetting(cc->contactID, META_PROTO, "ParentMeta", &dbv)) ? 0 : dbv.dVal; } sqlite3_finalize(stmt); } diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index d131681409..18ab712d76 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -28,7 +28,7 @@ static char *evt_stmts[SQL_EVT_STMT_NUM] = { "select flags from events where id = ? limit 1;", "update events set flag = ? where id = ?;", "select contactid from events where id = ? limit 1;", - "select id from events where contactid = ? order by id limit 1;", + "select min(id) from 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;", @@ -55,8 +55,13 @@ LONG CDbxSQLite::GetEventCount(MCONTACT hContact) { mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_COUNT]; + sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); - int count = sqlite3_column_int(stmt, 0); + if (rc != SQLITE_ROW) { + sqlite3_reset(stmt); + return 0; + } + LONG count = sqlite3_column_int64(stmt, 0); sqlite3_reset(stmt); return count; } @@ -94,7 +99,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, DBEVENTINFO *dbei) hDbEvent = sqlite3_last_insert_rowid(m_db); } - bool neednotify; + bool neednotify = false; if (!(dbei->flags & (DBEF_READ | DBEF_SENT))) neednotify = true; //else neednotify = m_safetyMode; @@ -139,7 +144,7 @@ LONG CDbxSQLite::GetBlobSize(MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_BLOBSIZE]; sqlite3_bind_int(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); - if (rc != SQLITE_DONE) { + if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return -1; } @@ -173,8 +178,14 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) dbei->timestamp = sqlite3_column_int64(stmt, 1); dbei->eventType = sqlite3_column_int(stmt, 2); dbei->flags = sqlite3_column_int64(stmt, 3); - dbei->cbBlob = sqlite3_column_int64(stmt, 4); - dbei->pBlob = (BYTE*)sqlite3_column_blob(stmt, 5); + + DWORD cbBlob = sqlite3_column_int64(stmt, 4); + int bytesToCopy = (dbei->cbBlob < cbBlob) ? dbei->cbBlob : cbBlob; + dbei->cbBlob = cbBlob; + if (bytesToCopy && dbei->pBlob) { + BYTE *data = (BYTE*)sqlite3_column_blob(stmt, 5); + memcpy(dbei->pBlob, data, dbei->cbBlob); + } sqlite3_reset(stmt); return 0; } @@ -342,7 +353,7 @@ MEVENT CDbxSQLite::FindPrevEvent(MCONTACT hContact, MEVENT hDbEvent) return 0; } hDbEvent = sqlite3_column_int64(stmt, 0); - sqlite3_finalize(stmt); + sqlite3_reset(stmt); return hDbEvent; } diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index e52da92919..8b73517791 100644 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -22,9 +22,9 @@ CDbxSQLite::~CDbxSQLite() DestroyHookableEvent(hEventMarkedRead); DestroyHookableEvent(hSettingChangeEvent); - InitContacts(); - InitEvents(); - InitSettings(); + UninitEvents(); + UninitContacts(); + UninitSettings(); if (m_db) { sqlite3_close(m_db); @@ -101,9 +101,9 @@ MDatabaseCommon* CDbxSQLite::Load(const wchar_t *profile, int readonly) sqlite3_exec(database, "commit;", nullptr, nullptr, nullptr); CDbxSQLite *db = new CDbxSQLite(database); + db->InitSettings(); db->InitContacts(); db->InitEvents(); - db->InitSettings(); return db; } diff --git a/plugins/Dbx_sqlite/src/stdafx.h b/plugins/Dbx_sqlite/src/stdafx.h index 0cf1b89f3d..4113213c7c 100644 --- a/plugins/Dbx_sqlite/src/stdafx.h +++ b/plugins/Dbx_sqlite/src/stdafx.h @@ -12,6 +12,7 @@ #include <m_system.h> #include <m_database.h> #include <m_db_int.h> +#include <m_metacontacts.h> #include "dbintf.h" #include "resource.h" |