Database.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Created by Иван_Архипов on 17.11.2017.
  3. //
  4. #ifndef LOTRO_DAT_PATCHER_DATABASE_H
  5. #define LOTRO_DAT_PATCHER_DATABASE_H
  6. #include <SQLite/sqlite3.h>
  7. #include <string>
  8. #include <yaml-cpp/yaml.h>
  9. extern "C++"
  10. {
  11. namespace LOTRO_DAT
  12. {
  13. class BinaryData;
  14. class SubfileData;
  15. class Database {
  16. public:
  17. Database();
  18. explicit Database(const std::string &filename);
  19. ~Database();
  20. void InitDatabase(const std::string &filename);
  21. void PushFile(const SubfileData &data);
  22. SubfileData GetNextFile();
  23. void RemoveDatabase();
  24. void ClearDatabase();
  25. size_t CountRows();
  26. private:
  27. void ExecSql(const std::string &sql);
  28. sqlite3* db_;
  29. sqlite3_stmt* insert_request_;
  30. sqlite3_stmt* fetch_one_request_;
  31. sqlite3_stmt* get_rows_number_request_;
  32. const std::string CreateTableCommand_ = "CREATE TABLE IF NOT EXISTS `patch_data` ( "
  33. "`binary_data` BLOB, "
  34. "`text_data` TEXT, "
  35. "`options` TEXT NOT NULL);";
  36. const std::string InsertFileCommand_ = "INSERT INTO `patch_data` "
  37. "(`binary_data`, `text_data`, `options`) "
  38. "VALUES (?, ?, ?); ";
  39. const std::string FetchOneCommand = "SELECT * FROM `patch_data`";
  40. const std::string ClearTableCommand_ = "DELETE * FROM `patch_data`";
  41. const std::string GetRowsNumberCommand_ = "SELECT Count(*) as count FROM `patch_data`";
  42. };
  43. }
  44. }
  45. #endif