db.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef DB_H
  2. #define DB_H
  3. #include <SQLiteCpp/SQLiteCpp.h>
  4. class DBData {
  5. SQLite::Database db;
  6. void create_tables(void);
  7. std::string user;
  8. /*
  9. I thought some of my performance problems were from the prepared statement
  10. calls. It was not the case, there's a weird delay when I save/hit the
  11. database. This didn't fix it, but they are still present.
  12. Prepared statements, prepared ahead of time, are a good thing.
  13. */
  14. std::unique_ptr<SQLite::Statement> stmt_getSet;
  15. std::unique_ptr<SQLite::Statement> stmt_setSet;
  16. public:
  17. DBData();
  18. virtual ~DBData();
  19. void setUser(std::string currentUser) { user = currentUser; };
  20. void clearUser(void) { user.clear(); };
  21. std::string getSetting(const std::string &setting, std::string ifMissing);
  22. void setSetting(const std::string &setting, const std::string &value);
  23. void saveScore(time_t when, time_t date, int hand, int score);
  24. int handsPlayedOnDay(time_t day);
  25. };
  26. void normalizeDate(time_t &tt, int hour = 2);
  27. std::string convertDateToDateScoreFormat(time_t tt);
  28. #endif