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