summaryrefslogtreecommitdiff
path: root/plugins/Dbx_sqlite/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_sqlite/src')
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp22
-rw-r--r--plugins/Dbx_sqlite/src/dbintf.cpp5
-rw-r--r--plugins/Dbx_sqlite/src/dbsettings.cpp12
3 files changed, 29 insertions, 10 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index 605090c2eb..0dadafa834 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -104,7 +104,9 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei)
}
mir_cslockfull lock(m_csDbAccess);
- sqlite3_stmt *stmt = InitQuery("INSERT INTO events(contact_id, module, timestamp, type, flags, data, server_id, is_read) VALUES (?, ?, ?, ?, ?, ?, ?, ?);", qEvAdd);
+ sqlite3_stmt *stmt = InitQuery(
+ "INSERT INTO events(contact_id, module, timestamp, type, flags, data, server_id, user_id, is_read) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);", qEvAdd);
sqlite3_bind_int64(stmt, 1, hContact);
sqlite3_bind_text(stmt, 2, tmp.szModule, (int)mir_strlen(tmp.szModule), nullptr);
sqlite3_bind_int64(stmt, 3, tmp.timestamp);
@@ -112,7 +114,8 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei)
sqlite3_bind_int64(stmt, 5, tmp.flags);
sqlite3_bind_blob(stmt, 6, tmp.pBlob, tmp.cbBlob, nullptr);
sqlite3_bind_text(stmt, 7, szEventId, (int)mir_strlen(szEventId), nullptr);
- sqlite3_bind_int(stmt, 8, tmp.markedRead());
+ sqlite3_bind_text(stmt, 8, tmp.szUserId, (int)mir_strlen(tmp.szUserId), nullptr);
+ sqlite3_bind_int(stmt, 9, tmp.markedRead());
int rc = sqlite3_step(stmt);
logError(rc, __FILE__, __LINE__);
sqlite3_reset(stmt);
@@ -287,7 +290,7 @@ int CDbxSQLite::GetBlobSize(MEVENT hDbEvent)
return res;
}
-static char g_szId[100];
+static char g_szId[100], g_szUserId[100];
BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
{
@@ -303,7 +306,7 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
}
mir_cslock lock(m_csDbAccess);
- sqlite3_stmt *stmt = InitQuery("SELECT module, timestamp, type, flags, server_id, length(data), data FROM events WHERE id = ? LIMIT 1;", qEvGet);
+ sqlite3_stmt *stmt = InitQuery("SELECT module, timestamp, type, flags, server_id, user_id, length(data), data FROM events WHERE id = ? LIMIT 1;", qEvGet);
sqlite3_bind_int64(stmt, 1, hDbEvent);
int rc = sqlite3_step(stmt);
logError(rc, __FILE__, __LINE__);
@@ -328,7 +331,14 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
}
else dbei->szId = nullptr;
- int32_t cbBlob = sqlite3_column_int64(stmt, 5);
+ char *pszUserId = (char *)sqlite3_column_text(stmt, 5);
+ if (mir_strlen(pszUserId)) {
+ mir_strncpy(g_szUserId, pszUserId, sizeof(g_szUserId));
+ dbei->szUserId = g_szUserId;
+ }
+ else dbei->szUserId = nullptr;
+
+ int32_t cbBlob = sqlite3_column_int64(stmt, 6);
size_t bytesToCopy = cbBlob;
if (dbei->cbBlob == -1)
dbei->pBlob = (uint8_t*)mir_calloc(cbBlob + 2);
@@ -337,7 +347,7 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
dbei->cbBlob = cbBlob;
if (bytesToCopy && dbei->pBlob) {
- uint8_t *data = (uint8_t *)sqlite3_column_blob(stmt, 6);
+ uint8_t *data = (uint8_t *)sqlite3_column_blob(stmt, 7);
if (dbei->flags & DBEF_ENCRYPTED) {
dbei->flags &= ~DBEF_ENCRYPTED;
diff --git a/plugins/Dbx_sqlite/src/dbintf.cpp b/plugins/Dbx_sqlite/src/dbintf.cpp
index 035a651ccf..95855925f5 100644
--- a/plugins/Dbx_sqlite/src/dbintf.cpp
+++ b/plugins/Dbx_sqlite/src/dbintf.cpp
@@ -46,7 +46,7 @@ int CDbxSQLite::Create()
logError(rc, __FILE__, __LINE__);
rc = sqlite3_exec(m_db, "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, is_read INTEGER NOT NULL DEFAULT 0);", nullptr, nullptr, nullptr);
+ "timestamp INTEGER NOT NULL, type INTEGER NOT NULL, flags INTEGER NOT NULL, data BLOB, server_id TEXT NULL, user_id TEXT NULL, is_read INTEGER NOT NULL DEFAULT 0);", nullptr, nullptr, nullptr);
logError(rc, __FILE__, __LINE__);
rc = sqlite3_exec(m_db, "CREATE INDEX idx_events_contactid_timestamp ON events(contact_id, timestamp);", nullptr, nullptr, nullptr);
@@ -67,6 +67,9 @@ int CDbxSQLite::Create()
rc = sqlite3_exec(m_db, "CREATE INDEX idx_settings_module ON settings(module);", nullptr, nullptr, nullptr);
logError(rc, __FILE__, __LINE__);
+
+ DBVARIANT dbv = { DBVT_BYTE, 2 };
+ WriteContactSetting(0, "Compatibility", "Sqlite", &dbv);
return 0;
}
diff --git a/plugins/Dbx_sqlite/src/dbsettings.cpp b/plugins/Dbx_sqlite/src/dbsettings.cpp
index c4bd196cb4..249a8bc059 100644
--- a/plugins/Dbx_sqlite/src/dbsettings.cpp
+++ b/plugins/Dbx_sqlite/src/dbsettings.cpp
@@ -59,7 +59,7 @@ void CDbxSQLite::InitSettings()
FillContactSettings();
- DBVARIANT dbv; dbv.type = DBVT_BYTE;
+ DBVARIANT dbv = { DBVT_BYTE };
if (GetContactSetting(0, "Compatibility", "Sqlite", &dbv))
dbv.bVal = 0;
@@ -73,8 +73,14 @@ void CDbxSQLite::InitSettings()
rc = sqlite3_exec(m_db, "UPDATE events SET is_read=1 WHERE (flags & 6) <> 0;", nullptr, nullptr, nullptr);
logError(rc, __FILE__, __LINE__);
- dbv.type = DBVT_BYTE;
- dbv.dVal = 1;
+ 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;
WriteContactSetting(0, "Compatibility", "Sqlite", &dbv);
}
}