SQL: change log type to integer using enum

master
Tomasz Golinski 2020-09-14 19:35:52 +02:00
rodzic a98472eb1c
commit c7d8d8ee53
2 zmienionych plików z 15 dodań i 5 usunięć

Wyświetl plik

@ -243,11 +243,11 @@ bool OCdb::update_log(const json& j) {
fields["user"] = j["data"]["user"]["uuid"].get<std::string>();
if (j["data"].count("type") && !j["data"]["type"].is_null()) {
if (j["data"]["type"].get<std::string>() == "Didn't find it")
fields2["type"] = 0;
fields2["type"] = dnf;
else if (j["data"]["type"].get<std::string>() == "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) {

6
ocdb.h
Wyświetl plik

@ -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();