Database.h 1.3 KB

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