diff options
author | George Hazan <george.hazan@gmail.com> | 2023-10-01 21:07:25 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-10-01 21:07:25 +0300 |
commit | a6821e1eefdbd4c428a62bfd41cb2bf1f9fa7f39 (patch) | |
tree | 78f72340a4465e5469de62016ee62dbc194af229 /plugins/Dbx_sqlite | |
parent | 1ad97c2cb09ab0348162e8cbb7af83df6c5c18bf (diff) |
Dbx_Sqlite: fix for events deletion
Diffstat (limited to 'plugins/Dbx_sqlite')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbcheck.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 26 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.h | 5 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbsettings.cpp | 7 |
4 files changed, 28 insertions, 12 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcheck.cpp b/plugins/Dbx_sqlite/src/dbcheck.cpp index 9a2a8d642b..661b87f1ff 100644 --- a/plugins/Dbx_sqlite/src/dbcheck.cpp +++ b/plugins/Dbx_sqlite/src/dbcheck.cpp @@ -38,7 +38,7 @@ int CDbxSQLite::CheckPhase2() MCONTACT hContact = sqlite3_column_int(pQuery, 1);
int64_t ts = sqlite3_column_int64(pQuery, 2);
- DeleteEventSrt(hDbEvent, hContact, ts);
+ DeleteEventSrt(hContact, ts);
cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned sorting event with wrong event ID %d:%08X, deleting"), hContact, hDbEvent));
}
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index 8dfb608bce..70766e48b1 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -187,12 +187,22 @@ int CDbxSQLite::DeleteEventMain(MEVENT hDbEvent) return rc;
}
-int CDbxSQLite::DeleteEventSrt(MEVENT hDbEvent, MCONTACT hContact, int64_t ts)
+int CDbxSQLite::DeleteEventSrt(MCONTACT hContact, int64_t ts)
{
- auto *stmt = InitQuery("DELETE FROM events_srt WHERE id = ? AND contact_id = ? AND timestamp = ?;", qEvDelSrt);
- sqlite3_bind_int64(stmt, 1, hDbEvent);
- sqlite3_bind_int64(stmt, 2, hContact);
- sqlite3_bind_int64(stmt, 3, ts);
+ auto *stmt = InitQuery("DELETE FROM events_srt WHERE contact_id = ? AND timestamp = ?;", qEvDelSrt);
+ sqlite3_bind_int64(stmt, 1, hContact);
+ sqlite3_bind_int64(stmt, 2, ts);
+ int rc = sqlite3_step(stmt);
+ logError(rc, __FILE__, __LINE__);
+ sqlite3_reset(stmt);
+ return rc;
+}
+
+int CDbxSQLite::DeleteEventSrt2(MCONTACT hContact, MEVENT hDbEvent)
+{
+ auto *stmt = InitQuery("DELETE FROM events_srt WHERE contact_id = ? AND id = ?;", qEvDelSrt2);
+ sqlite3_bind_int64(stmt, 1, hContact);
+ sqlite3_bind_int64(stmt, 2, hDbEvent);
int rc = sqlite3_step(stmt);
logError(rc, __FILE__, __LINE__);
sqlite3_reset(stmt);
@@ -205,9 +215,8 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent) return 1;
MEVENT hContact;
- uint32_t ts;
{
- sqlite3_stmt *stmt = InitQuery("SELECT contact_id, timestamp FROM events WHERE id = ? LIMIT 1;", qEvGetContact2);
+ sqlite3_stmt *stmt = InitQuery("SELECT contact_id FROM events WHERE id = ? LIMIT 1;", qEvGetContact2);
sqlite3_bind_int64(stmt, 1, hDbEvent);
int rc = sqlite3_step(stmt);
logError(rc, __FILE__, __LINE__);
@@ -216,7 +225,6 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent) return 2;
}
hContact = sqlite3_column_int64(stmt, 0);
- ts = sqlite3_column_int64(stmt, 1);
sqlite3_reset(stmt);
}
@@ -231,7 +239,7 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent) if (rc != SQLITE_DONE)
return 1;
- rc = DeleteEventSrt(hDbEvent, hContact, ts);
+ rc = DeleteEventSrt2(hContact, hDbEvent);
if (rc != SQLITE_DONE)
return 1;
diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index 0872fa1096..7f6447ffd7 100644 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -80,11 +80,12 @@ class CDbxSQLite : public MDatabaseCommon, public MIDatabaseChecker, public MZer void InitEvents();
void UninitEvents();
CQuery qEvAdd, qEvDel, qEvEdit1, qEvEdit2, qEvBlobSize, qEvGet, qEvGetFlags, qEvSetFlags, qEvGetContact, qEvGetContact2;
- CQuery qEvFindFirst, qEvFindNext, qEvFindLast, qEvFindPrev, qEvFindUnread, qEvAddSrt, qEvDelSrt, qEvMetaSplit, qEvMetaMerge;
+ CQuery qEvFindFirst, qEvFindNext, qEvFindLast, qEvFindPrev, qEvFindUnread, qEvAddSrt, qEvDelSrt, qEvDelSrt2, qEvMetaSplit, qEvMetaMerge;
CQuery qEvGetById, qEvUpdateId, qEvSetJson;
int AddEventSrt(MEVENT, MCONTACT, int64_t ts);
int DeleteEventMain(MEVENT);
- int DeleteEventSrt(MEVENT, MCONTACT, int64_t ts);
+ int DeleteEventSrt(MCONTACT, int64_t ts);
+ int DeleteEventSrt2(MCONTACT, MEVENT);
// settings
void InitSettings();
diff --git a/plugins/Dbx_sqlite/src/dbsettings.cpp b/plugins/Dbx_sqlite/src/dbsettings.cpp index 3bce34de20..691b3921f1 100644 --- a/plugins/Dbx_sqlite/src/dbsettings.cpp +++ b/plugins/Dbx_sqlite/src/dbsettings.cpp @@ -125,6 +125,13 @@ void CDbxSQLite::InitSettings() logError(rc, __FILE__, __LINE__);
dbv.bVal = 3;
+ }
+
+ if (dbv.bVal < 4) {
+ int rc = sqlite3_exec(m_db, "CREATE INDEX i1_srt ON events_srt(contact_id, id);", 0, 0, 0);
+ logError(rc, __FILE__, __LINE__);
+
+ dbv.bVal = 4;
WriteContactSetting(0, "Compatibility", "Sqlite", &dbv);
}
}
|