diff --git a/ocdb.cpp b/ocdb.cpp index a50d778..4b2f2bf 100644 --- a/ocdb.cpp +++ b/ocdb.cpp @@ -62,7 +62,7 @@ bool OCdb::init(std::string dump_path) { for (auto& el : j["data_files"].items()) { init_part(dump_path + el.value().get()); } - request("UPDATE revision SET revision = " + std::to_string(revision) + ';'); + request("COMMIT;"); return 1; } @@ -89,9 +89,8 @@ bool OCdb::update(Okapi& oc) { for (auto& el : j["changelog"].items()) { parse_item(el.value()); } - revision = j["revision"]; - request("UPDATE revision SET revision = " + std::to_string(revision) + ';'); - request("COMMIT"); + set_revision(j["revision"]); + request("COMMIT;"); if (j["more"]) update(oc); return 1; @@ -341,3 +340,12 @@ Caches OCdb::get_user_caches(std::string uuid, int count) { // sqlite3_finalize(stmt); return cc; } + +int OCdb::get_revision() { + return revision; +} + +void OCdb::set_revision(int rev) { + revision = rev; + request("UPDATE revision SET revision = " + std::to_string(revision) + ';'); +} diff --git a/ocdb.h b/ocdb.h index c09cdc8..6132918 100644 --- a/ocdb.h +++ b/ocdb.h @@ -16,6 +16,7 @@ class OCdb : public Api { private: sqlite3* db; sqlite3_stmt* stmt; + int revision; bool request(std::string req); bool init_part(std::string json_file); // read db dump @@ -24,13 +25,13 @@ private: bool update_log(json j); bool read_revision(); public: - int revision; - OCdb(std::string db_file); ~OCdb(); bool init(std::string json_file); // read db dump bool update(Okapi& oc); // apply changelog + int get_revision(); + void set_revision(int rev); Caches get_user_caches_not_found(std::string uuid); Caches get_user_caches(std::string uuid, int count = 0);