version 0.0.1
[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 \r
9 #include "../sqlite3db.h"\r
10 \r
11 namespace SQLite3DB\r
12 {\r
13 \r
14 class DB:public ZThread::Singleton<DB>\r
15 {\r
16 public:\r
17         DB();\r
18         DB(std::string filename);\r
19         ~DB();\r
20         \r
21         const bool Open(const std::string &filename);\r
22         const bool Close();\r
23         \r
24         const int GetLastResult() { return m_lastresult; }      // gets result of last action taken - standard sqlite3 return codes\r
25         const int GetLastError(std::string &errormessage);      // gets last error of this database\r
26         \r
27         const bool IsOpen();\r
28         \r
29         const bool Execute(const std::string &sql);     // executes a statement returing true if successful\r
30         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
31         Recordset Query(const std::string &sql);                // executes a statement returning a recordset\r
32         Statement Prepare(const std::string &sql);      // prepares a statement returning the statement object\r
33 \r
34         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
35 \r
36         sqlite3 *GetDB() { return m_db; }\r
37 \r
38         ZThread::Mutex m_mutex;                 // public so that recordset and statment can lock this mutex themselves\r
39 \r
40 private:\r
41         void Initialize();\r
42         \r
43         sqlite3 *m_db;\r
44         int m_lastresult;\r
45 };\r
46 \r
47 }       // namespace\r
48 \r
49 #endif  // _sqlite3db_\r