diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2020-05-24 22:06:52 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2020-05-24 22:06:52 +0300 |
commit | 2216a0138ffac6e6d9052083c23f8bdb75856457 (patch) | |
tree | 19d3fbf42e58a323f2a6e3893c693aaf1493724c /plugins | |
parent | e8ab5643c369d9c01b3aafe43628d9f1953c5384 (diff) |
implemented starting position support in cursors
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbevents.cpp | 28 | ||||
-rwxr-xr-x | plugins/Dbx_sqlite/src/dbintf.h | 2 |
2 files changed, 24 insertions, 6 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index 25755334a4..9c24ddb3f0 100755 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -25,9 +25,15 @@ enum { //TODO: hide it inside cursor class static const char* normal_order_query = "select id from events_srt where contact_id = ? order by timestamp;"; +static const char* normal_order_pos_query = +"select id from events_srt where contact_id = ? and id >= ? order by timestamp;"; + static const char* reverse_order_query = "select id from events_srt where contact_id = ? order by timestamp desc, id desc;"; +static const char* reverse_order_pos_query = +"select id from events_srt where contact_id = ? and id <= ? order by timestamp desc, id desc;"; + static const char *evt_stmts[SQL_EVT_STMT_NUM] = { "select count(1) from events where contact_id = ? limit 1;", @@ -720,22 +726,34 @@ BOOL CDbxSQLite::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact*) STDMETHODIMP_(DB::EventCursor*) CDbxSQLite::EventCursor(MCONTACT hContact, MEVENT hDbEvent) { - return new CDbxSQLiteEventCursor(hContact, m_db); + return new CDbxSQLiteEventCursor(hContact, m_db, hDbEvent); } STDMETHODIMP_(DB::EventCursor*) CDbxSQLite::EventCursorRev(MCONTACT hContact, MEVENT hDbEvent) { - return new CDbxSQLiteEventCursor(hContact, m_db, true); + return new CDbxSQLiteEventCursor(hContact, m_db, hDbEvent, true); } -CDbxSQLiteEventCursor::CDbxSQLiteEventCursor(MCONTACT _1, sqlite3* _db, bool reverse) +CDbxSQLiteEventCursor::CDbxSQLiteEventCursor(MCONTACT _1, sqlite3* _db, MEVENT hDbEvent, bool reverse) : EventCursor(_1), m_db(_db) { if (reverse) - sqlite3_prepare_v2(m_db, reverse_order_query, -1, &cursor, nullptr); + { + if (!hDbEvent) + sqlite3_prepare_v2(m_db, reverse_order_query, -1, &cursor, nullptr); + else + sqlite3_prepare_v2(m_db, reverse_order_pos_query, -1, &cursor, nullptr); + } else - sqlite3_prepare_v2(m_db, normal_order_query, -1, &cursor, nullptr); + { + if (!hDbEvent) + sqlite3_prepare_v2(m_db, normal_order_query, -1, &cursor, nullptr); + else + sqlite3_prepare_v2(m_db, normal_order_pos_query, -1, &cursor, nullptr); + } sqlite3_bind_int64(cursor, 1, hContact); + if (hDbEvent) + sqlite3_bind_int64(cursor, 2, hDbEvent); } CDbxSQLiteEventCursor::~CDbxSQLiteEventCursor() diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h index a1810f3f38..70d021f202 100755 --- a/plugins/Dbx_sqlite/src/dbintf.h +++ b/plugins/Dbx_sqlite/src/dbintf.h @@ -24,7 +24,7 @@ struct DBCachedContact : public DBCachedContactBase struct CDbxSQLiteEventCursor : public DB::EventCursor { - CDbxSQLiteEventCursor(MCONTACT _1, sqlite3* m_db, bool reverse = false); + CDbxSQLiteEventCursor(MCONTACT _1, sqlite3* m_db, MEVENT hDbEvent, bool reverse = false); ~CDbxSQLiteEventCursor() override; MEVENT FetchNext() override; private: |