db.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:当前项目数据库操作实现;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[11/13/2013];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef __DATA_IMPL__
  19. #define __DATA_IMPL__
  20. #pragma once
  21. #include "sqlite3.h"
  22. #include <vector>
  23. typedef struct __ST_REPORT__
  24. {
  25. std::string url;
  26. std::string content;
  27. std::string report_date;
  28. __ST_REPORT__& operator=(const __ST_REPORT__& that)
  29. {
  30. if (this != &that )
  31. {
  32. url = that.url;
  33. content = that.content;
  34. report_date = that.report_date;
  35. }
  36. return *this;
  37. }
  38. }STReport, *pSTReport;
  39. class CDataImpl
  40. {
  41. public:
  42. CDataImpl(void);
  43. virtual ~CDataImpl(void);
  44. // 私有变量;
  45. private:
  46. sqlite3 *m_psqlite3;
  47. // 用户函数;
  48. public:
  49. BOOL Open(std::string com);
  50. void Close();
  51. // begin;
  52. int TransactionBegin()
  53. {
  54. char* psqlite_error = NULL;
  55. INT nRet = sqlite3_exec(m_psqlite3, "begin;", 0, 0, &psqlite_error);
  56. if ( nRet != SQLITE_OK)
  57. {
  58. if ( psqlite_error )
  59. {
  60. sqlite3_free(psqlite_error);
  61. psqlite_error = NULL;
  62. }
  63. return nRet;
  64. }
  65. return SQLITE_OK;
  66. }
  67. // commit;
  68. int TransactionCommit()
  69. {
  70. char* psqlite_error = NULL;
  71. INT nRet = sqlite3_exec(m_psqlite3, "commit;", 0, 0, &psqlite_error);
  72. if ( nRet != SQLITE_OK)
  73. {
  74. if ( psqlite_error )
  75. {
  76. sqlite3_free(psqlite_error);
  77. psqlite_error = NULL;
  78. }
  79. return nRet;
  80. }
  81. return SQLITE_OK;
  82. }
  83. // 执行语句;
  84. BOOL ExecteSQL(IN LPCSTR lpSQL);
  85. // 查询表是否存在;
  86. BOOL QueryTable(std::string table);
  87. INT QueryReportInfo(std::vector<STReport>& vtdata);
  88. // 根据订单号查询订单信息;//返回查询数量;
  89. INT QueryUnReportInfo(std::vector<STReport> &vtdata);
  90. // 插入mid信息;
  91. INT InsertReportInfo(STReport& data);
  92. INT InsertReportInfo(std::string url, std::string content, bool report_status = false);
  93. INT InsertReportInfo(std::string content);
  94. INT InsertReportInfo(std::string report_type, std::map<std::string, std::string> report_data);
  95. // 删除已上报成功的记录(1个月前的);
  96. INT RemoveReportInfo();
  97. // 更新上报状态;
  98. BOOL UpdateKeyReportStatus(STReport& data);
  99. };
  100. #endif