diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Dbx_sqlite/res/dbx_sqlite.rc | 50 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.cpp | 114 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.h | 1 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbsettings.cpp | 97 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/resource.h | 6 |
5 files changed, 164 insertions, 104 deletions
diff --git a/plugins/Dbx_sqlite/res/dbx_sqlite.rc b/plugins/Dbx_sqlite/res/dbx_sqlite.rc index eca647170a..ca4e3cce5a 100644 --- a/plugins/Dbx_sqlite/res/dbx_sqlite.rc +++ b/plugins/Dbx_sqlite/res/dbx_sqlite.rc @@ -12,17 +12,12 @@ #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// -// Английский (США) resources +// English (United States) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // @@ -47,7 +42,48 @@ END #endif // APSTUDIO_INVOKED -#endif // Английский (США) resources + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_MSGBOX DIALOGEX 0, 0, 229, 47 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_CLIENTEDGE | WS_EX_APPWINDOW +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CTEXT "Converting database...",IDC_STATIC,21,17,186,8 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_MSGBOX, DIALOG + BEGIN + TOPMARGIN, 17 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// AFX_DIALOG_LAYOUT +// + +IDD_MSGBOX AFX_DIALOG_LAYOUT +BEGIN + 0 +END + +#endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// 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<MConvert> 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<MConvert> 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 |