version 0.1.11
[fms.git] / include / db / sqlite3db / sqlite3db.h
1 #ifndef _sqlite3db_\r
2 #define _sqlite3db_\r
3 \r
4 //#include <zthread/Singleton.h>\r
5 //#include <zthread/Mutex.h>\r
6 #include <sqlite3.h>\r
7 #include <string>\r
8 #include "../../pthreadwrapper/mutex.h"\r
9 #include "../sqlite3db.h"\r
10 \r
11 #include "../../pthreadwrapper/singleton.h"\r
12 \r
13 #if SQLITE_VERSION_NUMBER<3005000\r
14 #error "Your version of SQLite is too old!  3.5.0 or later is required."\r
15 #endif\r
16 \r
17 namespace SQLite3DB\r
18 {\r
19 \r
20 class DB:public PThread::Singleton<DB>\r
21 {\r
22 public:\r
23         DB();\r
24         DB(std::string filename);\r
25         ~DB();\r
26         \r
27         const bool Open(const std::string &filename);\r
28         const bool Close();\r
29         \r
30         const int GetLastResult() { return m_lastresult; }      // gets result of last action taken - standard sqlite3 return codes\r
31         const int GetLastError(std::string &errormessage);      // gets last error of this database\r
32         \r
33         const bool IsOpen();\r
34         \r
35         const bool Execute(const std::string &sql);     // executes a statement returing true if successful\r
36         const bool ExecuteInsert(const std::string &sql, long &insertid);       // call when inserting data and the insertid of the row inserted is needed, otherwise Execute can be called if the row id is not needed\r
37         Recordset Query(const std::string &sql);                // executes a statement returning a recordset\r
38         Statement Prepare(const std::string &sql);      // prepares a statement returning the statement object\r
39 \r
40         const int SetBusyTimeout(const int ms);         // sets busy timeout in ms.  SQLite will wait for a lock up to this many ms before returning SQLITE_BUSY\r
41 \r
42         sqlite3 *GetDB() { return m_db; }\r
43 \r
44         PThread::Mutex m_mutex;                 // public so that recordset and statment can lock this mutex themselves\r
45 \r
46 private:\r
47         void Initialize();\r
48         \r
49         sqlite3 *m_db;\r
50         int m_lastresult;\r
51 };\r
52 \r
53 }       // namespace\r
54 \r
55 #endif  // _sqlite3db_\r