Database.h 2.3 KB

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