From f1c4d08896d6bda7c89f7145f61f724513888b77 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 4 Nov 2023 18:45:14 +0300 Subject: =?UTF-8?q?fixes=20#3782=20(0.96.4:=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=82=D1=8C=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=20=D1=82=D0=BE=D0=BC,?= =?UTF-8?q?=20=D1=87=D1=82=D0=BE=20=D0=9C=D0=B8=D1=80=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=B2=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=B0,=20=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B8=D1=81=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D1=82=20=D0=BF=D1=80=D0=B5=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/Dbx_sqlite/src/dbintf.cpp | 114 ++++++++++++++++++++++++++++++++++ plugins/Dbx_sqlite/src/dbintf.h | 1 + plugins/Dbx_sqlite/src/dbsettings.cpp | 97 +---------------------------- plugins/Dbx_sqlite/src/resource.h | 6 +- 4 files changed, 121 insertions(+), 97 deletions(-) (limited to 'plugins/Dbx_sqlite/src') diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp index 70d35e9fbf..5d663be534 100644 --- a/plugins/Dbx_sqlite/src/dbintf.cpp +++ b/plugins/Dbx_sqlite/src/dbintf.cpp @@ -78,6 +78,120 @@ int CDbxSQLite::Create() ///////////////////////////////////////////////////////////////////////////////////////// +#define CURRVER 5 + +static INT_PTR CALLBACK MsbBoxWndProc(HWND, UINT uMsg, WPARAM, LPARAM) +{ + if (uMsg == WM_INITDIALOG) + return TRUE; + + return FALSE; +} + +void CDbxSQLite::CheckConversion() +{ + DBVARIANT dbv = { DBVT_BYTE }; + if (GetContactSettingWorker(0, "Compatibility", "Sqlite", &dbv, 0)) + dbv.bVal = 0; + + if (dbv.bVal >= CURRVER) + return; + + HWND hwndMsgBox = CreateDialogW(g_plugin.getInst(), MAKEINTRESOURCE(IDD_MSGBOX), 0, MsbBoxWndProc); + ShowWindow(hwndMsgBox, SW_NORMAL); + SetForegroundWindow(hwndMsgBox); + + if (dbv.bVal < 1) { + int rc = sqlite3_exec(m_db, "ALTER TABLE events ADD COLUMN is_read INTEGER NOT NULL DEFAULT 0;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + + rc = sqlite3_exec(m_db, "CREATE INDEX idx_events_isread ON events(contact_id, is_read, timestamp);", nullptr, nullptr, nullptr); + logError(rc, __FILE__, __LINE__); + + rc = sqlite3_exec(m_db, "UPDATE events SET is_read=1 WHERE (flags & 6) <> 0;", nullptr, nullptr, nullptr); + logError(rc, __FILE__, __LINE__); + } + + if (dbv.bVal < 2) { + int rc = sqlite3_exec(m_db, "ALTER TABLE events ADD COLUMN user_id TEXT NULL;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + } + + if (dbv.bVal < 3) { + int rc = sqlite3_exec(m_db, "UPDATE events_srt SET timestamp=timestamp*1000;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + + CQuery updateSql; + sqlite3_stmt *updateStmt = InitQuery("UPDATE events_srt SET timestamp=timestamp+? " + " WHERE rowid IN (SELECT rowid FROM events_srt WHERE contact_id=? AND timestamp=? LIMIT 1);", updateSql); + + sqlite3_stmt *pQuery; + rc = sqlite3_prepare_v2(m_db, "SELECT contact_id, timestamp, count(*) AS boo FROM events_srt GROUP BY contact_id, timestamp HAVING boo > 1;", -1, &pQuery, nullptr); + logError(rc, __FILE__, __LINE__); + + struct MConvert + { + MConvert(MCONTACT _1, int64_t _2, int _3) : + hContact(_1), + ts(_2), + iCount(_3) + {} + + MCONTACT hContact; + int iCount; + int64_t ts; + }; + + OBJLIST recs(10000); + while (sqlite3_step(pQuery) == SQLITE_ROW) { + MCONTACT hContact = sqlite3_column_int(pQuery, 0); + int64_t ts = sqlite3_column_int64(pQuery, 1); + int iCount = sqlite3_column_int(pQuery, 2); + recs.insert(new MConvert(hContact, ts, iCount)); + } + + for (auto &it : recs) { + for (int i = it->iCount - 1; i > 0; i--) { + sqlite3_bind_int64(updateStmt, 1, i); + sqlite3_bind_int64(updateStmt, 2, it->hContact); + sqlite3_bind_int64(updateStmt, 3, it->ts); + rc = sqlite3_step(updateStmt); + logError(rc, __FILE__, __LINE__); + sqlite3_reset(updateStmt); + } + } + + rc = sqlite3_exec(m_db, "CREATE TABLE tmp(id INTEGER NOT NULL, contact_id INTEGER NOT NULL, timestamp INTEGER, PRIMARY KEY(contact_id, timestamp));", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + + rc = sqlite3_exec(m_db, "INSERT INTO tmp SELECT * FROM events_srt;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + if (rc != 0) + return; + + rc = sqlite3_exec(m_db, "DROP TABLE events_srt;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + + rc = sqlite3_exec(m_db, "ALTER TABLE tmp RENAME TO events_srt;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + } + + if (dbv.bVal < 5) { + int rc = sqlite3_exec(m_db, "DROP INDEX IF EXISTS i1_srt;", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + + rc = sqlite3_exec(m_db, "CREATE INDEX i1_srt ON events_srt(id);", 0, 0, 0); + logError(rc, __FILE__, __LINE__); + } + + dbv.bVal = CURRVER; + WriteContactSetting(0, "Compatibility", "Sqlite", &dbv); + + DestroyWindow(hwndMsgBox); +} + +///////////////////////////////////////////////////////////////////////////////////////// + int CDbxSQLite::Check() { FILE *hFile = _wfopen(m_wszFileName, L"rb"); diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index 85183f35a7..40fffafda1 100644 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -92,6 +92,7 @@ class CDbxSQLite : public MDatabaseCommon, public MIDatabaseChecker, public MZer CQuery qSettModules, qSettWrite, qSettDel, qSettEnum, qSettChanges; int DeleteContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting); + void CheckConversion(); void DBFlush(bool bForce = false); sqlite3_stmt* InitQuery(const char *szQuery, CQuery &stmt); diff --git a/plugins/Dbx_sqlite/src/dbsettings.cpp b/plugins/Dbx_sqlite/src/dbsettings.cpp index 9a32ba9616..d2a23fbc20 100644 --- a/plugins/Dbx_sqlite/src/dbsettings.cpp +++ b/plugins/Dbx_sqlite/src/dbsettings.cpp @@ -58,102 +58,7 @@ void CDbxSQLite::InitSettings() sqlite3_finalize(stmt); FillContactSettings(); - - DBVARIANT dbv = { DBVT_BYTE }; - if (GetContactSettingWorker(0, "Compatibility", "Sqlite", &dbv, 0)) - dbv.bVal = 0; - - if (dbv.bVal < 1) { - int rc = sqlite3_exec(m_db, "ALTER TABLE events ADD COLUMN is_read INTEGER NOT NULL DEFAULT 0;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - rc = sqlite3_exec(m_db, "CREATE INDEX idx_events_isread ON events(contact_id, is_read, timestamp);", nullptr, nullptr, nullptr); - logError(rc, __FILE__, __LINE__); - - rc = sqlite3_exec(m_db, "UPDATE events SET is_read=1 WHERE (flags & 6) <> 0;", nullptr, nullptr, nullptr); - logError(rc, __FILE__, __LINE__); - - dbv.bVal = 1; - } - - if (dbv.bVal < 2) { - int rc = sqlite3_exec(m_db, "ALTER TABLE events ADD COLUMN user_id TEXT NULL;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - dbv.bVal = 2; - } - - if (dbv.bVal < 3) { - int rc = sqlite3_exec(m_db, "UPDATE events_srt SET timestamp=timestamp*1000;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - CQuery updateSql; - sqlite3_stmt *updateStmt = InitQuery("UPDATE events_srt SET timestamp=timestamp+? " - " WHERE rowid IN (SELECT rowid FROM events_srt WHERE contact_id=? AND timestamp=? LIMIT 1);", updateSql); - - sqlite3_stmt *pQuery; - rc = sqlite3_prepare_v2(m_db, "SELECT contact_id, timestamp, count(*) AS boo FROM events_srt GROUP BY contact_id, timestamp HAVING boo > 1;", -1, &pQuery, nullptr); - logError(rc, __FILE__, __LINE__); - - struct MConvert - { - MConvert(MCONTACT _1, int64_t _2, int _3) : - hContact(_1), - ts(_2), - iCount(_3) - {} - - MCONTACT hContact; - int iCount; - int64_t ts; - }; - - OBJLIST recs(10000); - while (sqlite3_step(pQuery) == SQLITE_ROW) { - MCONTACT hContact = sqlite3_column_int(pQuery, 0); - int64_t ts = sqlite3_column_int64(pQuery, 1); - int iCount = sqlite3_column_int(pQuery, 2); - recs.insert(new MConvert(hContact, ts, iCount)); - } - - for (auto &it: recs) { - for (int i = it->iCount - 1; i > 0; i--) { - sqlite3_bind_int64(updateStmt, 1, i); - sqlite3_bind_int64(updateStmt, 2, it->hContact); - sqlite3_bind_int64(updateStmt, 3, it->ts); - rc = sqlite3_step(updateStmt); - logError(rc, __FILE__, __LINE__); - sqlite3_reset(updateStmt); - } - } - - rc = sqlite3_exec(m_db, "CREATE TABLE tmp(id INTEGER NOT NULL, contact_id INTEGER NOT NULL, timestamp INTEGER, PRIMARY KEY(contact_id, timestamp));", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - rc = sqlite3_exec(m_db, "INSERT INTO tmp SELECT * FROM events_srt;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - if (rc != 0) - return; - - rc = sqlite3_exec(m_db, "DROP TABLE events_srt;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - rc = sqlite3_exec(m_db, "ALTER TABLE tmp RENAME TO events_srt;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - dbv.bVal = 3; - } - - if (dbv.bVal < 5) { - int rc = sqlite3_exec(m_db, "DROP INDEX IF EXISTS i1_srt;", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - rc = sqlite3_exec(m_db, "CREATE INDEX i1_srt ON events_srt(id);", 0, 0, 0); - logError(rc, __FILE__, __LINE__); - - dbv.bVal = 5; - WriteContactSetting(0, "Compatibility", "Sqlite", &dbv); - } + CheckConversion(); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Dbx_sqlite/src/resource.h b/plugins/Dbx_sqlite/src/resource.h index 61f0d676ae..9eb726c05f 100644 --- a/plugins/Dbx_sqlite/src/resource.h +++ b/plugins/Dbx_sqlite/src/resource.h @@ -1,10 +1,14 @@ //{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by W:\miranda-ng\plugins\Dbx_sqlite\res\dbx_sqlite.rc +// +#define IDD_MSGBOX 101 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 107 +#define _APS_NEXT_RESOURCE_VALUE 109 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1012 #define _APS_NEXT_SYMED_VALUE 101 -- cgit v1.2.3