CDataBaseOperate.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. //#pragma warning(disable:4251)
  3. #include <stdio.h>
  4. #include <windows.h>
  5. #include <mutex>
  6. #include <vector>
  7. #include <functional>
  8. #include "string.h"
  9. #include "CError.h"
  10. #include "sqlite3.h"
  11. #include "dt.h"
  12. #include "CppSQLite3.h"
  13. #ifdef DATABASEOPERATE_DLL
  14. #define DLL_DATABASEOPERATE_API __declspec(dllexport)
  15. #else
  16. #define DLL_DATABASEOPERATE_API
  17. #endif
  18. typedef std::function<void(string strDbName, string strTableName)> DataNoticeCallbackFun;
  19. namespace ns_db
  20. {
  21. typedef struct _TABLE_INFO_BASE
  22. {
  23. INT iNo_;
  24. _TABLE_INFO_BASE()
  25. {
  26. iNo_ = 100;
  27. }
  28. } TABLE_INFO_BASE;
  29. class DLL_DATABASEOPERATE_API CDataBaseOperate
  30. {
  31. private:
  32. bool m_bIsInit;
  33. //static void* context;
  34. static void* m_pPubSocket;
  35. static void* m_pSubscriberSocket;
  36. protected:
  37. CDataBaseOperate(string sPathFile);
  38. ~CDataBaseOperate();
  39. virtual LONG SaveDB() = 0;
  40. virtual LONG LoadDB() = 0;
  41. bool Open();
  42. void Close();
  43. CppSQLite3DB m_DB;
  44. std::string m_sPathFile = "";
  45. //设置表的缓存数据
  46. LONG SetTableData(string strTableName, vector<TABLE_INFO_BASE>* vecDB, vector<TABLE_INFO_BASE>* vecTemp, bool bAppend = false);
  47. public:
  48. string GetDbName() { return m_sPathFile; };
  49. //保存数据到数据库
  50. LONG SaveDataToDB();
  51. //从数据库加载数据
  52. LONG LoadDataByDB();
  53. //数据更改后发布通知
  54. LONG DataChangNotice(string strTableName);
  55. //接收数据更改后的通知
  56. void RecvDataChangNotice(string strTableName, DataNoticeCallbackFun callBackFun);
  57. };
  58. }