SQLite3Interface.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef __SQLITE3INTERFACE_H_
  2. #define __SQLITE3INTERFACE_H_
  3. /************************************************************************/
  4. /*
  5. 类名: CSQLiter3Interface
  6. 描述: sqlite3数据库操作
  7. */
  8. /************************************************************************/
  9. #include <string>
  10. #ifndef _UNICODE
  11. typedef std::string TString;
  12. #else
  13. typedef wstring TString;
  14. #endif
  15. struct sqlite3;
  16. // 创建表,注意:SQLite3每条SQL语句结束时需要加上分号;
  17. #define CREATE_DB_TBL_ "create table remoteinfo(\
  18. [domain] text not null,\
  19. [shopname] text not null,\
  20. [ipaddr] text not null,\
  21. [pcname] text not null,\
  22. [sharedir] text not null,\
  23. PRIMARY KEY([domain]));"
  24. //////////////////////////////////////////////////////////////////////////
  25. // 唯一的应用程序对象
  26. typedef struct _STRemoteInfo_
  27. {
  28. int bInUse;
  29. TCHAR szBranch[MAX_PATH];
  30. TCHAR szIP[MAX_PATH];
  31. TCHAR szDoMain[MAX_PATH];
  32. }STRemoteInfo,*pSTRemoteInfo;
  33. class CSQLiter3Interface
  34. {
  35. CSQLiter3Interface();
  36. public:
  37. ~CSQLiter3Interface();
  38. static CSQLiter3Interface* GetInstance()
  39. {
  40. static CSQLiter3Interface db;
  41. return &db;
  42. }
  43. //打开
  44. int OpenSQLite3DB(const char* pDBPath);
  45. //创建表
  46. int CreateTabel(const char* pSql, CString& strError);
  47. //执行
  48. int Exec(const char* pSql, CString& strError);
  49. //错误消息
  50. const char* Get_ErrMsg();
  51. //查询
  52. int Select(const char* pTableName, const char* pFields, const char* pLimit, std::vector<TString>& vValues, CString& strError);
  53. //插入
  54. int Insert(const char* pTableName, const char* pFields, const char* pValues, CString& strError);
  55. //删除
  56. int Delete(const char* pTableName, const char* pLimit, CString& strError);
  57. //关闭
  58. int Close();
  59. private:
  60. sqlite3* m_pSqli3db;
  61. };
  62. #endif