1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#pragma once
#define OWN_CACHED_CONTACT
#include <m_db_int.h>
struct DBCachedContact : public DBCachedContactBase
{
uint32_t m_count;
MEVENT m_first;
uint32_t m_firstTimestamp;
MEVENT m_unread;
uint32_t m_unreadTimestamp;
MEVENT m_last;
uint32_t m_lastTimestamp;
DBCachedContact()
: m_count(-1), m_first(0), m_unread(0), m_last(0) { }
bool HasCount() const;
void AddEvent(MEVENT hDbEvent, uint32_t timestamp, bool unread);
void EditEvent(MEVENT hDbEvent, uint32_t timestamp, bool unread);
void DeleteEvent(MEVENT hDbEvent);
void MarkRead(MEVENT hDbEvent);
};
struct CDbxSQLite : public MDatabaseCommon, public MZeroedObject
{
private:
sqlite3 *m_db;
sqlite3_stmt *evt_cur_fwd = nullptr, *evt_curr_backwd = nullptr;
MCONTACT evt_cnt_fwd = 0, evt_cnt_backwd = 0;
DBCachedContact m_system;
bool m_safetyMode;
CDbxSQLite(sqlite3 *database);
void InitContacts();
void UninitContacts();
LIST<char> m_modules;
void InitEvents();
void UninitEvents();
void InitSettings();
void UninitSettings();
public:
~CDbxSQLite();
static int Create(const wchar_t *profile);
static int Check(const wchar_t *profile);
static MDatabaseCommon* Load(const wchar_t *profile, int readonly);
STDMETHODIMP_(BOOL) IsRelational(void) override;
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL) override;
STDMETHODIMP_(LONG) GetContactCount(void) override;
STDMETHODIMP_(LONG) DeleteContact(MCONTACT contactID) override;
STDMETHODIMP_(MCONTACT) AddContact(void) override;
STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID) override;
STDMETHODIMP_(LONG) GetContactSize(void) override;
STDMETHODIMP_(LONG) GetEventCount(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(LONG) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
STDMETHODIMP_(MCONTACT) GetEventContact(MEVENT hDbEvent) override;
STDMETHODIMP_(MEVENT) FindFirstEvent(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) FindFirstUnreadEvent(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) FindLastEvent(MCONTACT contactID) override;
STDMETHODIMP_(MEVENT) FindNextEvent(MCONTACT contactID, MEVENT hDbEvent) override;
STDMETHODIMP_(MEVENT) FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent) override;
STDMETHODIMP_(MEVENT) GetEventById(LPCSTR szModule, LPCSTR szId) override;
STDMETHODIMP_(BOOL) SetEventId(LPCSTR szModule, MEVENT, LPCSTR szId) override;
STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam) override;
STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) override;
STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) override;
STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) override;
STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param) override;
STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override;
STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override;
STDMETHODIMP_(BOOL) Compact() override;
STDMETHODIMP_(BOOL) Backup(LPCWSTR) override;
};
|