diff options
Diffstat (limited to 'plugins/Dbx_sqlite')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbcontacts.cpp | 14 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 109 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.cpp | 20 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.h | 2 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbsettings.cpp | 56 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/stdafx.h | 1 |
6 files changed, 113 insertions, 89 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcontacts.cpp b/plugins/Dbx_sqlite/src/dbcontacts.cpp index 6a8568e2cb..882b04d30e 100644 --- a/plugins/Dbx_sqlite/src/dbcontacts.cpp +++ b/plugins/Dbx_sqlite/src/dbcontacts.cpp @@ -20,12 +20,10 @@ void CDbxSQLite::InitContacts() for (size_t i = 0; i < SQL_CTC_STMT_NUM; i++) sqlite3_prepare_v3(m_db, ctc_stmts[i], -1, SQLITE_PREPARE_PERSISTENT, &ctc_stmts_prep[i], nullptr); - // add global contact - //m_cache->AddContactToCache(0); - sqlite3_stmt *stmt = nullptr; - sqlite3_prepare_v2(m_db, "select contact_events.contactid, count(eventid) from contact_events join contacts on contacts.id = contact_events.contactid group by contact_events.contactid;", -1, &stmt, nullptr); - while (sqlite3_step(stmt) == SQLITE_ROW) { + sqlite3_prepare_v2(m_db, "select contacts.id, count(event_id) from contacts left join contact_events on contact_events.contact_id = contacts.id group by contacts.id;", -1, &stmt, nullptr); + int rc = 0; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { MCONTACT hContact = sqlite3_column_int64(stmt, 0); DBCachedContact *cc = (hContact) ? m_cache->AddContactToCache(hContact) @@ -45,6 +43,7 @@ void CDbxSQLite::InitContacts() 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; } + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_finalize(stmt); } @@ -58,7 +57,8 @@ LONG CDbxSQLite::GetContactCount() { mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = ctc_stmts_prep[SQL_CTC_STMT_COUNT]; - sqlite3_step(stmt); + int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); int count = sqlite3_column_int(stmt, 0); sqlite3_reset(stmt); return count; @@ -71,6 +71,7 @@ MCONTACT CDbxSQLite::AddContact() mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = ctc_stmts_prep[SQL_CTC_STMT_ADD]; int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return INVALID_CONTACT_ID; @@ -96,6 +97,7 @@ LONG CDbxSQLite::DeleteContact(MCONTACT hContact) sqlite3_stmt *stmt = ctc_stmts_prep[SQL_CTC_STMT_DELETE]; sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index b02d49a929..0bdec1190f 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -24,25 +24,25 @@ enum { }; static char *evt_stmts[SQL_EVT_STMT_NUM] = { - "select count(1) from contact_events where contactid = ? limit 1;", - "insert into events(module, timestamp, type, flags, size, blob) values (?, ?, ?, ?, ?, ?);", - "insert into contact_events(contactid, eventid, timestamp) values (?, ?, ?);", - "delete from contact_events where contactid = ?1 and eventid = ?2; delete from events where id = ?2;", + "select count(1) from contact_events where contact_id = ? limit 1;", + "insert into events(module, timestamp, type, flags, size, data) values (?, ?, ?, ?, ?, ?);", + "insert into contact_events(contact_id, event_id, timestamp) values (?, ?, ?);", + "delete from contact_events where contact_id = ?1 and event_id = ?2; delete from events where id = ?2;", "update events set module = ?, timestamp = ?, type = ?, flags = ?, size = ?, blob = ? where id = ?;", "select size from events where id = ? limit 1;", - "select module, timestamp, type, flags, size, blob from events where id = ? limit 1;", + "select module, timestamp, type, flags, size, data from events where id = ? limit 1;", "select flags from events where id = ? limit 1;", - "update events set flag = ? where id = ?;", - "select contactid from contact_events where eventid = ? limit 1;", - "select eventid from contact_events where contactid = ? order by timestamp, eventid limit 1;", - "select events.id from events join contact_events on contact_events.eventid = events.id where contact_events.contactid = ? and (events.flags & (4 | 2)) = 0 order by events.timestamp, events.id limit 1;", - "select eventid from contact_events where contactid = ? order by timestamp desc, eventid desc limit 1;", - "select eventid from contact_events where contactid = ?1 and eventid <> ?2 and timestamp > (select timestamp from contact_events where contactid = ?1 and eventid = ?2 limit 1) order by timestamp, eventid limit 1;", - "select eventid from contact_events where contactid = ? and eventid <> ? and timestamp < (select timestamp from contact_events where contactid = ?1 and eventid = ?2 limit 1) order by timestamp desc, eventid desc limit 1;", - "select id from events where module = ? and serverid = ? limit 1;", - "update events set serverid = ? where id = ?;", - "insert into contact_events(contactid, eventid, timestamp) select ?1, eventid, timestamp from contact_events where contactid = ?2 order by timestamp, eventid;", - "delete from contact_events where contactid = ? and eventid in (select eventid from contact_events where contactid = ?);", + "update events set flags = ? where id = ?;", + "select contact_id from contact_events where event_id = ? limit 1;", + "select event_id from contact_events where contact_id = ? order by timestamp, event_id limit 1;", + "select events.id from events join contact_events on contact_events.event_id = events.id where contact_events.contact_id = ? and (events.flags & ?) = 0 order by events.timestamp, events.id limit 1;", + "select event_id from contact_events where contact_id = ? order by timestamp desc, event_id desc limit 1;", + "select event_id from contact_events where contact_id = ?1 and event_id <> ?2 and timestamp > (select timestamp from contact_events where contact_id = ?1 and event_id = ?2 limit 1) order by timestamp, event_id limit 1;", + "select event_id from contact_events where contact_id = ? and event_id <> ? and timestamp < (select timestamp from contact_events where contact_id = ?1 and event_id = ?2 limit 1) order by timestamp desc, event_id desc limit 1;", + "select id from events where module = ? and server_id = ? limit 1;", + "update events set server_id = ? where id = ?;", + "insert into contact_events(contact_id, event_id, timestamp) select ?1, event_id, timestamp from contact_events where contact_id = ?2 order by timestamp, event_id;", + "delete from contact_events where contact_id = ? and event_id in (select event_id from contact_events where contact_id = ?);", }; static sqlite3_stmt *evt_stmts_prep[SQL_EVT_STMT_NUM] = { 0 }; @@ -72,6 +72,7 @@ LONG CDbxSQLite::GetEventCount(MCONTACT hContact) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_COUNT]; sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -89,14 +90,33 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, DBEVENTINFO *dbei) if (dbei->timestamp == 0) return 0; - DBCachedContact *cc = (hContact) - ? m_cache->GetCachedContact(hContact) - : &m_system; + MCONTACT hNotifyContact = hContact; + DBCachedContact *cc, *ccSub = nullptr; + if (hContact != 0) { + if ((cc = m_cache->GetCachedContact(hContact)) == nullptr) + return 0; + + if (cc->IsSub()) { + ccSub = cc; + if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr) + return 0; + + // set default sub to the event's source + if (!(dbei->flags & DBEF_SENT)) + db_mc_setDefault(cc->contactID, hContact, false); + hContact = cc->contactID; // and add an event to a metahistory + if (db_mc_isEnabled()) + hNotifyContact = hContact; + } + } + else cc = &m_system; + if (cc == nullptr) return 0; - if (NotifyEventHooks(hEventFilterAddedEvent, hContact, (LPARAM)dbei)) - return 0; + if (m_safetyMode) + if (NotifyEventHooks(hEventFilterAddedEvent, hNotifyContact, (LPARAM)dbei)) + return 0; MEVENT hDbEvent = 0; { @@ -111,6 +131,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, DBEVENTINFO *dbei) sqlite3_bind_int64(stmt, 5, dbei->cbBlob); sqlite3_bind_blob(stmt, 6, dbei->pBlob, dbei->cbBlob, nullptr); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) { sqlite3_exec(m_db, "rollback;", nullptr, nullptr, nullptr); @@ -123,28 +144,37 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, DBEVENTINFO *dbei) sqlite3_bind_int64(stmt, 2, hDbEvent); sqlite3_bind_int64(stmt, 3, dbei->timestamp); rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) { sqlite3_exec(m_db, "rollback;", nullptr, nullptr, nullptr); return 0; } + // insert an event into a sub's history too + if (ccSub != nullptr) { + sqlite3_bind_int64(stmt, 1, ccSub->contactID); + sqlite3_bind_int64(stmt, 2, hDbEvent); + sqlite3_bind_int64(stmt, 3, dbei->timestamp); + rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); + sqlite3_reset(stmt); + if (rc != SQLITE_DONE) { + sqlite3_exec(m_db, "rollback;", nullptr, nullptr, nullptr); + return 0; + } + } + sqlite3_exec(m_db, "commit;", nullptr, nullptr, nullptr); cc->count++; cc->first = cc->last = 0; - if (!(dbei->flags & (DBEF_READ | DBEF_SENT))) + if (!dbei->markedRead()) cc->unread = 0; } - bool neednotify = false; - if (!(dbei->flags & (DBEF_READ | DBEF_SENT))) - neednotify = true; - //else neednotify = m_safetyMode; - - // notify only in safe mode or on really new events - if (neednotify) - NotifyEventHooks(hEventAddedEvent, hContact, (LPARAM)hDbEvent); + if (m_safetyMode) + NotifyEventHooks(hEventAddedEvent, hNotifyContact, (LPARAM)hDbEvent); return hDbEvent; } @@ -166,6 +196,7 @@ BOOL CDbxSQLite::DeleteEvent(MCONTACT hContact, MEVENT hDbEvent) sqlite3_bind_int64(stmt, 1, hContact); sqlite3_bind_int64(stmt, 2, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -205,6 +236,7 @@ BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, DBEVENTINFO *dbei sqlite3_bind_blob(stmt, 6, dbei->pBlob, dbei->cbBlob, nullptr); sqlite3_bind_int64(stmt, 7, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc == SQLITE_DONE) { cc->first = cc->unread = cc->last = 0; NotifyEventHooks(hEventEditedEvent, hContact, (LPARAM)hDbEvent); @@ -222,6 +254,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); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return -1; @@ -248,6 +281,7 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_GET]; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 1; @@ -285,6 +319,7 @@ BOOL CDbxSQLite::MarkEventRead(MCONTACT hContact, MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_GETFLAGS]; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return -1; @@ -303,7 +338,8 @@ BOOL CDbxSQLite::MarkEventRead(MCONTACT hContact, MEVENT hDbEvent) sqlite3_bind_int(stmt, 1, flags); sqlite3_bind_int64(stmt, 2, hDbEvent); int rc = sqlite3_step(stmt); - sqlite3_reset(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); + sqlite3_reset(stmt); if (rc != SQLITE_DONE) return -1; if (cc->unread = hDbEvent) @@ -324,6 +360,7 @@ MCONTACT CDbxSQLite::GetEventContact(MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_GETCONTACT]; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return INVALID_CONTACT_ID; @@ -348,6 +385,7 @@ MEVENT CDbxSQLite::FindFirstEvent(MCONTACT hContact) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_FINDFIRST]; sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -371,7 +409,9 @@ MEVENT CDbxSQLite::FindFirstUnreadEvent(MCONTACT hContact) mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_FINDFIRSTUNREAD]; sqlite3_bind_int64(stmt, 1, hContact); + sqlite3_bind_int(stmt, 2, DBEF_READ | DBEF_SENT); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -396,6 +436,7 @@ MEVENT CDbxSQLite::FindLastEvent(MCONTACT hContact) sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_FINDLAST]; sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -419,6 +460,7 @@ MEVENT CDbxSQLite::FindNextEvent(MCONTACT hContact, MEVENT hDbEvent) sqlite3_bind_int64(stmt, 1, hContact); sqlite3_bind_int64(stmt, 2, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -442,6 +484,7 @@ MEVENT CDbxSQLite::FindPrevEvent(MCONTACT hContact, MEVENT hDbEvent) sqlite3_bind_int64(stmt, 1, hContact); sqlite3_bind_int64(stmt, 2, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -461,6 +504,7 @@ MEVENT CDbxSQLite::GetEventById(LPCSTR szModule, LPCSTR szId) sqlite3_bind_text(stmt, 1, szModule, mir_strlen(szModule), nullptr); sqlite3_bind_text(stmt, 2, szId, mir_strlen(szId), nullptr); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -480,6 +524,7 @@ BOOL CDbxSQLite::SetEventId(LPCSTR, MEVENT hDbEvent, LPCSTR szId) sqlite3_bind_text(stmt, 1, szId, mir_strlen(szId), nullptr); sqlite3_bind_int64(stmt, 2, hDbEvent); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); return (rc != SQLITE_DONE); } @@ -491,6 +536,7 @@ BOOL CDbxSQLite::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSu sqlite3_bind_int64(stmt, 1, ccMeta->contactID); sqlite3_bind_int64(stmt, 2, ccSub->contactID); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); ccMeta->first = ccMeta->unread = ccMeta->last = 0; return (rc != SQLITE_DONE); @@ -503,6 +549,7 @@ BOOL CDbxSQLite::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSu sqlite3_bind_int64(stmt, 1, ccMeta->contactID); sqlite3_bind_int64(stmt, 2, ccSub->contactID); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); ccMeta->first = ccMeta->unread = ccMeta->last = 0; return (rc != SQLITE_DONE); diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index 36fabaa76c..dc204d1b4e 100644 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -1,7 +1,8 @@ #include "stdafx.h" CDbxSQLite::CDbxSQLite(sqlite3 *database) - : m_db(database) + : m_db(database), + m_safetyMode(true) { hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED); hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED); @@ -34,7 +35,6 @@ CDbxSQLite::~CDbxSQLite() } } - int CDbxSQLite::Create(const wchar_t *profile) { sqlite3 *database = nullptr; @@ -43,12 +43,13 @@ int CDbxSQLite::Create(const wchar_t *profile) if (rc != SQLITE_OK) return 1; - sqlite3_exec(database, "create table contacts (id integer not null primary key);", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create table events (id integer not null primary key, module varchar(255) not null, timestamp integer not null, type integer not null, flags integer not null, size integer not null, blob any, serverid varchar(64));", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create index idx_events on events(module, serverid);", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create table contact_events (contactid integer not null, eventid integer not null, timestamp integer not null, primary key(contactid, eventid)) without rowid;", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create table settings (contactid integer not null, module varchar(255) not null, setting varchar(255) not null, type integer not null, value any, primary key(contactid, module, setting)) without rowid;", nullptr, nullptr, nullptr); - sqlite3_exec(database, "create index idx_settings on settings(contactid, module, setting);", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create table contacts (id integer not null primary key autoincrement);", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create table events (id integer not null primary key autoincrement, timestamp integer not null, type integer not null, flags integer not null, size integer not null, data blob, module varchar(255) not null, server_id varchar(64));", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create index idx_events_module_serverid on events(module, server_id);", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create table contact_events (contact_id integer not null, event_id integer not null, timestamp integer not null, primary key(contact_id, event_id)) without rowid;", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create index idx_contact_events_eventid on contact_events(event_id);", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create table settings (contact_id integer not null, module varchar(255) not null, setting varchar(255) not null, type integer not null, value any, primary key(contact_id, module, setting)) without rowid;", nullptr, nullptr, nullptr); + sqlite3_exec(database, "create index idx_settings_module on settings(module);", nullptr, nullptr, nullptr); sqlite3_close(database); @@ -143,6 +144,7 @@ BOOL CDbxSQLite::IsRelational() return TRUE; } -void CDbxSQLite::SetCacheSafetyMode(BOOL) +void CDbxSQLite::SetCacheSafetyMode(BOOL value) { + m_safetyMode = value != FALSE; } diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index 4d919212ec..98c07991ce 100644 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -30,6 +30,8 @@ private: DBCachedContact m_system; + bool m_safetyMode; + CDbxSQLite(sqlite3 *database); void InitContacts(); diff --git a/plugins/Dbx_sqlite/src/dbsettings.cpp b/plugins/Dbx_sqlite/src/dbsettings.cpp index f238d3fb08..ddf35afbb9 100644 --- a/plugins/Dbx_sqlite/src/dbsettings.cpp +++ b/plugins/Dbx_sqlite/src/dbsettings.cpp @@ -11,10 +11,10 @@ enum { static char *settings_stmts[SQL_SET_STMT_NUM] = { "select distinct module from settings;", - "select type, value from settings where contactid = ? and module = ? and setting = ? limit 1;", - "replace into settings(contactid, module, setting, type, value) values (?, ?, ?, ?, ?);", - "delete from settings where contactid = ? and module = ? and setting = ?;", - "select setting from settings where contactid = ? and module = ?;" + "select type, value from settings where contact_id = ? and module = ? and setting = ? limit 1;", + "replace into settings(contact_id, module, setting, type, value) values (?, ?, ?, ?, ?);", + "delete from settings where contact_id = ? and module = ? and setting = ?;", + "select setting from settings where contact_id = ? and module = ?;" }; static sqlite3_stmt *settings_stmts_prep[SQL_SET_STMT_NUM] = { 0 }; @@ -23,43 +23,6 @@ void CDbxSQLite::InitSettings() { for (size_t i = 0; i < SQL_SET_STMT_NUM; i++) sqlite3_prepare_v3(m_db, settings_stmts[i], -1, SQLITE_PREPARE_PERSISTENT, &settings_stmts_prep[i], nullptr); - /*DBVARIANT dbv = {}; - sqlite3_stmt *stmt = nullptr; - sqlite3_prepare_v2(m_db, "select contactid, module, setting, type, value from settings", -1, &stmt, nullptr); - while (sqlite3_step(stmt) == SQLITE_ROW) { - MCONTACT hContact = sqlite3_column_int64(stmt, 0); - const char *module = (const char*)sqlite3_column_text(stmt, 1); - const char *setting = (const char*)sqlite3_column_text(stmt, 2); - dbv.type = sqlite3_column_int(stmt, 3); - switch (dbv.type) { - case DBVT_BYTE: - dbv.bVal = sqlite3_column_int(stmt, 4); - break; - case DBVT_WORD: - dbv.wVal = sqlite3_column_int(stmt, 4); - break; - case DBVT_DWORD: - dbv.dVal = sqlite3_column_int64(stmt, 4); - break; - case DBVT_ASCIIZ: - { - char *utf8 = mir_strdup((const char*)sqlite3_column_text(stmt, 4)); - dbv.pszVal = mir_utf8decode(utf8, nullptr); - break; - } - case DBVT_UTF8: - dbv.pszVal = mir_strdup((const char*)sqlite3_column_text(stmt, 4)); - break; - case DBVT_BLOB: - continue; - } - char *cachedSettingName = m_cache->GetCachedSetting(module, setting, mir_strlen(module), mir_strlen(setting)); - DBVARIANT *cachedValue = m_cache->GetCachedValuePtr(hContact, cachedSettingName, 1); - m_cache->SetCachedVariant(&dbv, cachedValue); - if(dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) - mir_free(dbv.pszVal); - } - sqlite3_finalize(stmt);*/ } void CDbxSQLite::UninitSettings() @@ -73,10 +36,12 @@ BOOL CDbxSQLite::EnumModuleNames(DBMODULEENUMPROC pFunc, void *param) LIST<char> modules(100); { sqlite3_stmt *stmt = settings_stmts_prep[SQL_SET_STMT_ENUM]; - while (sqlite3_step(stmt) == SQLITE_ROW) { + int rc = 0; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { const char *value = (const char*)sqlite3_column_text(stmt, 0); modules.insert(mir_strdup(value)); } + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); } @@ -153,6 +118,7 @@ LBL_Seek: sqlite3_bind_text(stmt, 2, szModule, mir_strlen(szModule), nullptr); sqlite3_bind_text(stmt, 3, szSetting, mir_strlen(szSetting), nullptr); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); if (rc == SQLITE_DONE && cc && cc->IsMeta() && ValidLookupName(szModule, szSetting)) { @@ -307,6 +273,7 @@ BOOL CDbxSQLite::WriteContactSetting(MCONTACT hContact, DBCONTACTWRITESETTING *d break; } int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -338,6 +305,7 @@ BOOL CDbxSQLite::DeleteContactSetting(MCONTACT hContact, LPCSTR szModule, LPCSTR sqlite3_bind_text(stmt, 2, szModule, mir_strlen(szModule), nullptr); sqlite3_bind_text(stmt, 3, szSetting, mir_strlen(szSetting), nullptr); int rc = sqlite3_step(stmt); + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -371,10 +339,12 @@ BOOL CDbxSQLite::EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnu sqlite3_stmt *stmt = settings_stmts_prep[SQL_SET_STMT_ENUMMODULE]; sqlite3_bind_int64(stmt, 1, hContact); sqlite3_bind_text(stmt, 2, szModule, mir_strlen(szModule), nullptr); - while (sqlite3_step(stmt) == SQLITE_ROW) { + int rc = 0; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { const char *value = (const char*)sqlite3_column_text(stmt, 0); settings.insert(mir_strdup(value)); } + assert(rc == SQLITE_ROW || rc == SQLITE_DONE); sqlite3_reset(stmt); } diff --git a/plugins/Dbx_sqlite/src/stdafx.h b/plugins/Dbx_sqlite/src/stdafx.h index 80384e86da..91d20b4109 100644 --- a/plugins/Dbx_sqlite/src/stdafx.h +++ b/plugins/Dbx_sqlite/src/stdafx.h @@ -7,6 +7,7 @@ #include <newpluginapi.h> #include <win2k.h> +#include <assert.h> #include <m_core.h> #include <m_system.h> |