Database.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "Common/SQLite/sqlite3.h"
  7. #include <string>
  8. extern "C++"
  9. {
  10. namespace LOTRO_DAT
  11. {
  12. class BinaryData;
  13. class Database {
  14. public:
  15. Database();
  16. explicit Database(const std::string &filename);
  17. ~Database();
  18. void InitDatabase(const std::string &filename);
  19. void PushTextFile(long long file_id, long long gossip_id, const char16_t *text, const char *args, int dat_id = 0);
  20. //BinaryData& GetTextFile(long long file_id);
  21. void PushBinaryFile(long long file_id, const BinaryData& data);
  22. //BinaryData& GetBinaryFile(long long file_id);
  23. private:
  24. void ExecSql(const std::string &sql);
  25. sqlite3* db_;
  26. sqlite3_stmt* insert_text_;
  27. sqlite3_stmt* insert_binary_;
  28. sqlite3_stmt* get_text_;
  29. sqlite3_stmt* get_binary_;
  30. unsigned long long query_size_;
  31. const unsigned long long QUERY_MAX_SIZE = 210241024;
  32. const std::string CreateBinaryTableCommand_ = "CREATE TABLE IF NOT EXISTS `binary_data` ( "
  33. "`file_id` INTEGER NOT NULL DEFAULT '0', "
  34. "`data` BLOB, "
  35. "`dat_id` INTEGER NOT NULL DEFAULT '-1', "
  36. "PRIMARY KEY (`file_id`));";
  37. const std::string CreateTextTableCommand_ = "CREATE TABLE IF NOT EXISTS `text_data` ( "
  38. "`file_id` INTEGER NOT NULL DEFAULT '0', "
  39. "`gossip_id` INTEGER NOT NULL DEFAULT '0', "
  40. "`content` TEXT, "
  41. "`args` TEXT, "
  42. "`args_order` TEXT, "
  43. "`dat_id` INTEGER NOT NULL DEFAULT '-1', "
  44. "PRIMARY KEY (`file_id`, `gossip_id`));";
  45. const std::string InsertTextCommand_ = "INSERT INTO text_data "
  46. "(file_id, gossip_id, content, args) "
  47. "VALUES (?, ?, ?, ?); ";
  48. const std::string InsertBinaryCommand_ = "INSERT INTO binary_data "
  49. "(file_id, data) "
  50. "VALUES (?, ?); ";
  51. };
  52. }
  53. }
  54. #endif