diff --git a/ocdb.cpp b/ocdb.cpp index 5e7a791..b9950d9 100644 --- a/ocdb.cpp +++ b/ocdb.cpp @@ -243,11 +243,11 @@ bool OCdb::update_log(const json& j) { fields["user"] = j["data"]["user"]["uuid"].get(); if (j["data"].count("type") && !j["data"]["type"].is_null()) { if (j["data"]["type"].get() == "Didn't find it") - fields2["type"] = 0; + fields2["type"] = dnf; else if (j["data"]["type"].get() == "Found it") - fields2["type"] = 1; + fields2["type"] = found; else - fields2["type"] = -1; + fields2["type"] = other; } if (fields.empty()) return 1; @@ -322,7 +322,9 @@ Caches OCdb::get_user_caches_not_found(const std::string& uuid) const { sql = "SELECT code, location, region FROM caches WHERE status = "; sql += ok; - sql += " AND NOT EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = 1 and user = ?1) AND owner != ?1;"; + sql += " AND NOT EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = "; + sql += found; + sql += " and user = ?1) AND owner != ?1;"; res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL); if (res != SQLITE_OK) { @@ -356,7 +358,9 @@ Caches OCdb::get_user_caches(const std::string& uuid, __attribute__((unused)) in int res; //code TEXT PRIMARY KEY, name TEXT, location TEXT, type TEXT, status INTEGER, size TEXT, difficulty INTEGER, terrain INTEGER, country TEXT, region TEXT, owner TEXT) - sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name FROM caches WHERE EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = 1 and user = ?);"; + sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name FROM caches WHERE EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = "; + sql += found; + sql += " and user = ?);"; res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL); if (res != SQLITE_OK) { diff --git a/ocdb.h b/ocdb.h index f8049d1..b9285a6 100644 --- a/ocdb.h +++ b/ocdb.h @@ -28,6 +28,12 @@ private: bool read_revision(); Caches parse_sql_caches() const; + enum LogType { + found = 1, + dnf = 0, + other = -1 + }; + public: explicit OCdb(const std::string& db_file); ~OCdb();