forked from uroni/urbackup_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.h
95 lines (66 loc) · 2.4 KB
/
Database.h
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
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "Interface/DatabaseInt.h"
#include "Interface/Types.h"
#include "Interface/Mutex.h"
#include "Interface/Condition.h"
#include "Interface/SharedMutex.h"
struct sqlite3;
class CQuery;
const int c_sqlite_busy_timeout_default=10000; //10 seconds
class CDatabase : public IDatabaseInt
{
public:
bool Open(std::string pFile, const std::vector<std::pair<std::string,std::string> > &attach,
size_t allocation_chunk_size, ISharedMutex* single_user_mutex, IMutex* lock_mutex,
int* lock_count, ICondition *unlock_cond, const str_map& params);
~CDatabase();
virtual db_results Read(std::string pQuery);
virtual bool Write(std::string pQuery);
virtual bool BeginReadTransaction();
virtual bool BeginWriteTransaction();
virtual bool EndTransaction(void);
virtual bool RollbackTransaction();
virtual IQuery* Prepare(std::string pQuery, bool autodestroy=true);
virtual IQuery* Prepare(int id, std::string pQuery);
virtual void destroyQuery(IQuery *q);
virtual void destroyAllQueries(void);
virtual _i64 getLastInsertID(void);
sqlite3 *getDatabase(void);
//private function
bool WaitForUnlock(void);
bool LockForTransaction(void);
void UnlockForTransaction(void);
bool isInTransaction(void);
static void initMutex(void);
static void destroyMutex(void);
virtual bool Import(const std::string &pFile);
virtual bool Dump(const std::string &pFile);
virtual std::string getEngineName(void);
virtual void DetachDBs(void);
virtual void AttachDBs(void);
virtual bool Backup(const std::string &pFile, IBackupProgress* progress);
virtual void freeMemory();
virtual int getLastChanges();
virtual std::string getTempDirectoryPath();
virtual void lockForSingleUse();
virtual void unlockForSingleUse();
ISharedMutex* getSingleUseMutex();
private:
DATABASE_ID database_id;
bool backup_db(const std::string &pFile, const std::string &pDB, IBackupProgress* progress);
sqlite3 *db;
bool in_transaction;
std::vector<CQuery*> queries;
std::map<int, IQuery*> prepared_queries;
IMutex* lock_mutex;
int* lock_count;
ICondition *unlock_cond;
ISharedMutex* single_user_mutex;
std::auto_ptr<IScopedReadLock> transaction_read_lock;
std::auto_ptr<IScopedWriteLock> write_lock;
std::vector<std::pair<std::string,std::string> > attached_dbs;
str_map params;
};