OCdb: get name for found and owned caches, don't get it for not found.

sql-rework
Tomasz Golinski 2020-08-05 01:32:32 +02:00
rodzic c1958baa11
commit 7e3e9adb56
1 zmienionych plików z 6 dodań i 6 usunięć

Wyświetl plik

@ -315,7 +315,7 @@ Caches OCdb::get_user_caches_not_found(const std::string& uuid) const {
int res;
Caches cc;
sql = "SELECT code, location, name, region FROM caches WHERE status = 'Available' AND NOT EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = 1 and user = ?1) AND owner != ?1;";
sql = "SELECT code, location, region FROM caches WHERE status = 'Available' AND NOT EXISTS (SELECT cache_code FROM logs WHERE cache_code = code AND type = 1 and user = ?1) AND owner != ?1;";
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
if (res != SQLITE_OK) {
@ -329,9 +329,8 @@ Caches OCdb::get_user_caches_not_found(const std::string& uuid) const {
while (res == SQLITE_ROW) {
Cache c;
if (sqlite3_column_text(stmt, 0)) c.code = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
if (sqlite3_column_text(stmt, 1)) c.pos = Position(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
if (sqlite3_column_text(stmt, 2)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2));
if (sqlite3_column_text(stmt, 3)) c.region = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3));
if (sqlite3_column_text(stmt, 1)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1));
if (sqlite3_column_text(stmt, 2)) c.region = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2));
c.status = ok;
cc.push_back(c);
res = sqlite3_step(stmt);
@ -350,7 +349,7 @@ 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 TEXT, size TEXT, difficulty REAL, terrain REAL, country TEXT, region TEXT, owner TEXT)
sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status 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 = 1 and user = ?);";
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
if (res != SQLITE_OK) {
@ -367,7 +366,7 @@ Caches OCdb::get_user_caches_owned(const std::string& uuid) const {
Caches cc;
//code TEXT PRIMARY KEY, name TEXT, location TEXT, type TEXT, status TEXT, size TEXT, difficulty REAL, terrain REAL, country TEXT, region TEXT, owner TEXT)
sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status FROM caches WHERE owner = ?;";
sql = "SELECT code, location, type, size, difficulty, terrain, country, region, owner, status, name FROM caches WHERE owner = ?;";
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
if (res != SQLITE_OK) {
@ -395,6 +394,7 @@ Caches OCdb::parse_sql_caches() const {
//c.country = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6));
if (sqlite3_column_text(stmt, 7)) c.region = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7));
if (sqlite3_column_text(stmt, 8)) c.owner_uuid = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 8)); // TODO: we don't know owner's nick
if (sqlite3_column_text(stmt, 10)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 10));
if (sqlite3_column_text(stmt, 9)) {
std::string tmp = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 9));