diff options
author | George Hazan <ghazan@miranda.im> | 2021-01-31 20:36:20 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-01-31 20:36:20 +0300 |
commit | c6b493f65d7d768782852b6379c663161b63695f (patch) | |
tree | a1801a5fb24bc824141706a13668e823cf502e26 /plugins | |
parent | f09905686074cac363f5e66b5fc6deafc661e912 (diff) |
Dbx_sqlite:
- advanced error handling;
- a profile is always opened in exclusive mode;
- fixes #2717 (wrong query in line 115);
- fixes #2694 (two Mirandas can open the same profile, but the second one fails);
- version bump
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbcontacts.cpp | 14 | ||||
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbevents.cpp | 54 | ||||
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbintf.cpp | 72 | ||||
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbsettings.cpp | 10 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/utils.cpp | 12 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/version.h | 2 |
7 files changed, 92 insertions, 74 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcontacts.cpp b/plugins/Dbx_sqlite/src/dbcontacts.cpp index f9c32981cf..740330921e 100755 --- a/plugins/Dbx_sqlite/src/dbcontacts.cpp +++ b/plugins/Dbx_sqlite/src/dbcontacts.cpp @@ -32,7 +32,7 @@ void CDbxSQLite::InitContacts() DBCachedContact *cc = (hContact) ? m_cache->AddContactToCache(hContact) : &m_system; cc->m_count = sqlite3_column_int64(stmt, 1); } - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_finalize(stmt); } @@ -47,7 +47,7 @@ LONG CDbxSQLite::GetContactCount() mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = ctc_stmts[SQL_CTC_STMT_COUNT].pQuery; int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); int count = sqlite3_column_int(stmt, 0); sqlite3_reset(stmt); return count; @@ -60,7 +60,7 @@ MCONTACT CDbxSQLite::AddContact() mir_cslock lock(m_csDbAccess); sqlite3_stmt *stmt = ctc_stmts[SQL_CTC_STMT_ADD].pQuery; int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return INVALID_CONTACT_ID; @@ -87,7 +87,7 @@ LONG CDbxSQLite::DeleteContact(MCONTACT hContact) sqlite3_stmt *stmt = ctc_stmts[SQL_CTC_STMT_DELETEEVENTS].pQuery; sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -95,7 +95,7 @@ LONG CDbxSQLite::DeleteContact(MCONTACT hContact) stmt = ctc_stmts[SQL_CTC_STMT_DELETEEVENTS_SRT].pQuery; sqlite3_bind_int64(stmt, 1, hContact); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -103,7 +103,7 @@ LONG CDbxSQLite::DeleteContact(MCONTACT hContact) stmt = ctc_stmts[SQL_CTC_STMT_DELETESETTINGS].pQuery; sqlite3_bind_int64(stmt, 1, hContact); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -111,7 +111,7 @@ LONG CDbxSQLite::DeleteContact(MCONTACT hContact) stmt = ctc_stmts[SQL_CTC_STMT_DELETE].pQuery; sqlite3_bind_int64(stmt, 1, hContact); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); 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 7204aea647..4fa873adaf 100755 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -65,7 +65,7 @@ void CDbxSQLite::InitEvents() if (mir_strlen(module) > 0) m_modules.insert(mir_strdup(module)); } - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_finalize(stmt); } @@ -90,7 +90,7 @@ LONG CDbxSQLite::GetEventCount(MCONTACT hContact) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_COUNT].pQuery; sqlite3_bind_int64(stmt, 1, hContact); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); cc->m_count = (rc != SQLITE_ROW) ? 0 : sqlite3_column_int64(stmt, 0); sqlite3_reset(stmt); return cc->m_count; @@ -149,7 +149,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei) sqlite3_bind_blob(stmt, 6, dbei->pBlob, dbei->cbBlob, nullptr); sqlite3_bind_text(stmt, 7, szEventId, (int)mir_strlen(szEventId), nullptr); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); MEVENT hDbEvent = sqlite3_last_insert_rowid(m_db); @@ -159,7 +159,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei) sqlite3_bind_int64(stmt, 2, cc->contactID); sqlite3_bind_int64(stmt, 3, dbei->timestamp); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); cc->AddEvent(hDbEvent, dbei->timestamp, !dbei->markedRead()); @@ -169,7 +169,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei) sqlite3_bind_int64(stmt, 2, ccSub->contactID); sqlite3_bind_int64(stmt, 3, dbei->timestamp); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); //is this necessary ? ccSub->AddEvent(hDbEvent, dbei->timestamp, !dbei->markedRead()); @@ -202,7 +202,7 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_DELETE].pQuery; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -210,7 +210,7 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent) stmt = evt_stmts[SQL_EVT_STMT_DELETE_SRT].pQuery; sqlite3_bind_int64(stmt, 1, hDbEvent); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -247,7 +247,7 @@ BOOL CDbxSQLite::EditEvent(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO sqlite3_bind_blob(stmt, 5, dbei->pBlob, dbei->cbBlob, nullptr); sqlite3_bind_int64(stmt, 6, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); cc->EditEvent(hDbEvent, dbei->timestamp, !dbei->markedRead()); @@ -274,7 +274,7 @@ LONG CDbxSQLite::GetBlobSize(MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_BLOBSIZE].pQuery; sqlite3_bind_int(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return -1; @@ -302,7 +302,7 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_GET].pQuery; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 1; @@ -343,7 +343,7 @@ BOOL CDbxSQLite::MarkEventRead(MCONTACT hContact, MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_GETFLAGS].pQuery; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return -1; @@ -362,7 +362,7 @@ BOOL CDbxSQLite::MarkEventRead(MCONTACT hContact, MEVENT hDbEvent) sqlite3_bind_int(stmt, 1, flags); sqlite3_bind_int64(stmt, 2, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return -1; @@ -386,7 +386,7 @@ MCONTACT CDbxSQLite::GetEventContact(MEVENT hDbEvent) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_GETCONTACT].pQuery; sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return INVALID_CONTACT_ID; @@ -413,7 +413,7 @@ MEVENT CDbxSQLite::FindFirstEvent(MCONTACT hContact) sqlite3_bind_int64(evt_cur_fwd, 1, hContact); int rc = sqlite3_step(evt_cur_fwd); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { //empty response //reset sql cursor @@ -453,7 +453,7 @@ MEVENT CDbxSQLite::FindFirstUnreadEvent(MCONTACT hContact) sqlite3_stmt *stmt; sqlite3_prepare_v2(m_db, query, -1, &stmt, nullptr); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_finalize(stmt); return 0; @@ -468,7 +468,7 @@ MEVENT CDbxSQLite::FindFirstUnreadEvent(MCONTACT hContact) sqlite3_bind_int64(stmt, 1, hContact); sqlite3_bind_int(stmt, 2, DBEF_READ | DBEF_SENT); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -495,7 +495,7 @@ MEVENT CDbxSQLite::FindLastEvent(MCONTACT hContact) evt_cur_backwd = evt_stmts[SQL_EVT_STMT_FINDLAST].pQuery; sqlite3_bind_int64(evt_cur_backwd, 1, hContact); int rc = sqlite3_step(evt_cur_backwd); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { //empty response //reset sql cursor @@ -531,7 +531,7 @@ MEVENT CDbxSQLite::FindNextEvent(MCONTACT hContact, MEVENT hDbEvent) while (hDbEvent != sqlite3_column_int64(evt_cur_fwd, 0)) { int rc = sqlite3_step(evt_cur_fwd); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc == SQLITE_DONE) { //reset sql cursor sqlite3_reset(evt_cur_fwd); @@ -543,7 +543,7 @@ MEVENT CDbxSQLite::FindNextEvent(MCONTACT hContact, MEVENT hDbEvent) } int rc = sqlite3_step(evt_cur_fwd); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { //reset sql cursor sqlite3_reset(evt_cur_fwd); @@ -580,7 +580,7 @@ MEVENT CDbxSQLite::FindPrevEvent(MCONTACT hContact, MEVENT hDbEvent) while (hDbEvent != sqlite3_column_int64(evt_cur_backwd, 0)) { int rc = sqlite3_step(evt_cur_backwd); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc == SQLITE_DONE) { //reset sql cursor sqlite3_reset(evt_cur_backwd); @@ -592,7 +592,7 @@ MEVENT CDbxSQLite::FindPrevEvent(MCONTACT hContact, MEVENT hDbEvent) } int rc = sqlite3_step(evt_cur_backwd); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { //reset sql cursor sqlite3_reset(evt_cur_backwd); @@ -616,7 +616,7 @@ MEVENT CDbxSQLite::GetEventById(LPCSTR szModule, LPCSTR szId) sqlite3_bind_text(stmt, 1, szModule, (int)mir_strlen(szModule), nullptr); sqlite3_bind_text(stmt, 2, szId, (int)mir_strlen(szId), nullptr); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { sqlite3_reset(stmt); return 0; @@ -633,17 +633,17 @@ BOOL CDbxSQLite::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSu sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_META_MERGE_SELECT].pQuery; sqlite3_bind_int64(stmt, 1, ccSub->contactID); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); while (rc == SQLITE_ROW) { sqlite3_stmt *stmt2 = evt_stmts[SQL_EVT_STMT_ADDEVENT_SRT].pQuery; sqlite3_bind_int64(stmt2, 1, sqlite3_column_int64(stmt, 0)); sqlite3_bind_int64(stmt2, 2, ccMeta->contactID); sqlite3_bind_int64(stmt2, 3, sqlite3_column_int64(stmt, 1)); int rc2 = sqlite3_step(stmt2); - logError(rc2); + logError(rc2, __FILE__, __LINE__); sqlite3_reset(stmt2); rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); } sqlite3_reset(stmt); @@ -657,7 +657,7 @@ BOOL CDbxSQLite::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *) sqlite3_stmt *stmt = evt_stmts[SQL_EVT_STMT_META_SPLIT].pQuery; sqlite3_bind_int64(stmt, 1, ccMeta->contactID); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -708,7 +708,7 @@ MEVENT CDbxSQLiteEventCursor::FetchNext() return 0; int rc = sqlite3_step(cursor); - logError(rc); + logError(rc, __FILE__, __LINE__); if (rc != SQLITE_ROW) { //empty response //reset sql cursor diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index e0f45a7e18..474aaad4a5 100755 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -11,7 +11,7 @@ CDbxSQLite::CDbxSQLite(sqlite3 *database) : CDbxSQLite::~CDbxSQLite() { int rc = sqlite3_exec(m_db, "commit;", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); UninitEvents(); UninitContacts(); @@ -19,7 +19,7 @@ CDbxSQLite::~CDbxSQLite() if (m_db) { rc = sqlite3_close(m_db); - logError(rc); + logError(rc, __FILE__, __LINE__); m_db = nullptr; } @@ -29,34 +29,36 @@ int CDbxSQLite::Create(const wchar_t *profile) { sqlite3 *database = nullptr; ptrA path(mir_utf8encodeW(profile)); - int rc = sqlite3_open_v2(path, &database, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, nullptr); - logError(rc); - if (rc != SQLITE_OK) + int rc = sqlite3_open_v2(path, &database, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_EXCLUSIVE, nullptr); + logError(rc, __FILE__, __LINE__); + if (rc != SQLITE_OK) { + logError(rc, __FILE__, __LINE__); return 1; + } rc = sqlite3_exec(database, "CREATE TABLE contacts (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(database, "CREATE TABLE events (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, contact_id INTEGER NOT NULL, module TEXT NOT NULL," "timestamp INTEGER NOT NULL, type INTEGER NOT NULL, flags INTEGER NOT NULL, data BLOB, server_id TEXT);", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(database, "CREATE INDEX idx_events_contactid_timestamp ON events(contact_id, timestamp);", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(database, "CREATE INDEX idx_events_module_serverid ON events(module, server_id);", nullptr, nullptr, nullptr); if (rc != SQLITE_OK) - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(database, "CREATE TABLE events_srt (id INTEGER NOT NULL, contact_id INTEGER NOT NULL, timestamp INTEGER, PRIMARY KEY(contact_id, timestamp, id));", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(database, "CREATE TABLE settings (contact_id INTEGER NOT NULL, module TEXT NOT NULL, setting TEXT NOT NULL, type INTEGER NOT NULL, value ANY," "PRIMARY KEY(contact_id, module, setting)) WITHOUT ROWID;", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(database, "CREATE INDEX idx_settings_module ON settings(module);", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_close(database); return 0; @@ -83,9 +85,11 @@ int CDbxSQLite::Check(const wchar_t *profile) sqlite3 *database = nullptr; ptrA path(mir_utf8encodeW(profile)); - int rc = sqlite3_open_v2(path, &database, SQLITE_OPEN_READONLY, nullptr); - if (rc != SQLITE_OK) + int rc = sqlite3_open_v2(path, &database, SQLITE_OPEN_READONLY | SQLITE_OPEN_EXCLUSIVE, nullptr); + if (rc != SQLITE_OK) { + logError(rc, __FILE__, __LINE__); return EGROKPRF_DAMAGED; + } sqlite3_close(database); @@ -96,24 +100,28 @@ MDatabaseCommon* CDbxSQLite::Load(const wchar_t *profile, int readonly) { sqlite3 *database = nullptr; ptrA path(mir_utf8encodeW(profile)); - int flags = SQLITE_OPEN_READWRITE; + int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_EXCLUSIVE; if (readonly) flags |= SQLITE_OPEN_READONLY; int rc = sqlite3_open_v2(path, &database, flags, nullptr); - if (rc != SQLITE_OK) + if (rc != SQLITE_OK) { + logError(rc, __FILE__, __LINE__); return nullptr; + } - rc = sqlite3_exec(database, "begin transaction;", nullptr, nullptr, nullptr); - logError(rc); - - sqlite3_exec(database, "pragma locking_mode = EXCLUSIVE;", nullptr, nullptr, nullptr); - sqlite3_exec(database, "pragma synchronous = NORMAL;", nullptr, nullptr, nullptr); - sqlite3_exec(database, "pragma foreign_keys = OFF;", nullptr, nullptr, nullptr); - sqlite3_exec(database, "pragma journal_mode = OFF;", nullptr, nullptr, nullptr); - - rc = sqlite3_exec(database, "commit;", nullptr, nullptr, nullptr); - logError(rc); + rc = sqlite3_exec(database, "pragma locking_mode = EXCLUSIVE;", nullptr, nullptr, nullptr); + logError(rc, __FILE__, __LINE__); + rc = sqlite3_exec(database, "pragma synchronous = NORMAL;", nullptr, nullptr, nullptr); + logError(rc, __FILE__, __LINE__); + rc = sqlite3_exec(database, "pragma foreign_keys = OFF;", nullptr, nullptr, nullptr); + logError(rc, __FILE__, __LINE__); + rc = sqlite3_exec(database, "pragma journal_mode = OFF;", nullptr, nullptr, nullptr); + logError(rc, __FILE__, __LINE__); + if (rc == SQLITE_BUSY) { + sqlite3_close(database); + return nullptr; + } CDbxSQLite *db = new CDbxSQLite(database); db->InitContacts(); @@ -126,7 +134,7 @@ MDatabaseCommon* CDbxSQLite::Load(const wchar_t *profile, int readonly) } rc = sqlite3_exec(database, "begin transaction;", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); return db; } @@ -134,9 +142,11 @@ BOOL CDbxSQLite::Backup(LPCWSTR profile) { sqlite3 *database = nullptr; ptrA path(mir_utf8encodeW(profile)); - int rc = sqlite3_open_v2(path, &database, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, nullptr); - if (rc != SQLITE_OK) + int rc = sqlite3_open_v2(path, &database, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_EXCLUSIVE, nullptr); + if (rc != SQLITE_OK) { + logError(rc, __FILE__, __LINE__); return FALSE; + } mir_cslock lock(m_csDbAccess); @@ -163,10 +173,10 @@ void CDbxSQLite::DBFlush(bool bForce) mir_cslock lck(m_csDbAccess); int rc = sqlite3_exec(m_db, "commit;", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); rc = sqlite3_exec(m_db, "begin transaction;", nullptr, nullptr, nullptr); - logError(rc); + logError(rc, __FILE__, __LINE__); } else if (m_safetyMode) m_impl.m_timer.Start(50); diff --git a/plugins/Dbx_sqlite/src/dbsettings.cpp b/plugins/Dbx_sqlite/src/dbsettings.cpp index 45c77dbf06..bc00dbb918 100755 --- a/plugins/Dbx_sqlite/src/dbsettings.cpp +++ b/plugins/Dbx_sqlite/src/dbsettings.cpp @@ -100,7 +100,7 @@ BOOL CDbxSQLite::EnumModuleNames(DBMODULEENUMPROC pFunc, void *param) const char *value = (const char *)sqlite3_column_text(stmt, 0); modules.insert(mir_strdup(value)); } - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); } @@ -142,7 +142,7 @@ BOOL CDbxSQLite::WriteContactSettingWorker(MCONTACT hContact, DBCONTACTWRITESETT } int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); if (rc != SQLITE_DONE) return 1; @@ -172,11 +172,11 @@ BOOL CDbxSQLite::DeleteContactSetting(MCONTACT hContact, LPCSTR szModule, LPCSTR sqlite3_bind_text(stmt, 2, szModule, (int)mir_strlen(szModule), nullptr); sqlite3_bind_text(stmt, 3, szSetting, (int)mir_strlen(szSetting), nullptr); int rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); stmt = settings_stmts[SQL_SET_STMT_CHANGES].pQuery; rc = sqlite3_step(stmt); - logError(rc); + logError(rc, __FILE__, __LINE__); int deleted = sqlite3_column_int(stmt, 0); sqlite3_reset(stmt); if (deleted == 0) @@ -220,7 +220,7 @@ BOOL CDbxSQLite::EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnu const char *value = (const char *)sqlite3_column_text(stmt, 0); settings.insert(mir_strdup(value)); } - logError(rc); + logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); } diff --git a/plugins/Dbx_sqlite/src/stdafx.h b/plugins/Dbx_sqlite/src/stdafx.h index 9cb2103537..90cba22430 100644 --- a/plugins/Dbx_sqlite/src/stdafx.h +++ b/plugins/Dbx_sqlite/src/stdafx.h @@ -24,7 +24,7 @@ struct CQuery sqlite3_stmt *pQuery; }; -void logError(int rc, const char *szFile = __FILE__, int line = __LINE__); +void logError(int rc, const char *szFile, int line); ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Dbx_sqlite/src/utils.cpp b/plugins/Dbx_sqlite/src/utils.cpp index 174fe9d394..5c3202fef5 100644 --- a/plugins/Dbx_sqlite/src/utils.cpp +++ b/plugins/Dbx_sqlite/src/utils.cpp @@ -1,4 +1,7 @@ #include "stdafx.h" +#include <time.h> + +static HANDLE hLogger; void logError(int rc, const char *szFile, int line) { @@ -9,6 +12,11 @@ void logError(int rc, const char *szFile, int line) return; } - _ASSERT(rc == 0); - Netlib_Logf(0, "SQLITE error %d (%s, %d)", rc, szFile, line); + if (hLogger == nullptr) { + wchar_t wszFileName[MAX_PATH]; + wsprintf(wszFileName, L"C:\\Users\\user\\Desktop\\sqlite.%d.log", (int)time(0)); + hLogger = mir_createLog("mdbx", L"mdbx", wszFileName, 0); + } + + mir_writeLogA(hLogger, "sqlite: assertion failed (%s, %d): %d\n", szFile, line, rc); } diff --git a/plugins/Dbx_sqlite/src/version.h b/plugins/Dbx_sqlite/src/version.h index e4eca01863..5f086b9e31 100644 --- a/plugins/Dbx_sqlite/src/version.h +++ b/plugins/Dbx_sqlite/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 95 #define __RELEASE_NUM 13 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include <stdver.h> |