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