kopia lustrzana https://gitlab.com/tomaszg/geostat
Another run of clang-format
rodzic
dc42212e31
commit
b40b29de80
25
geodb.cpp
25
geodb.cpp
|
@ -13,7 +13,6 @@ using json = nlohmann::json;
|
|||
|
||||
const std::string Database = "ocpl.sqlite";
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string Dump_path;
|
||||
bool update = 0;
|
||||
|
@ -24,7 +23,6 @@ int main(int argc, char** argv) {
|
|||
case 'd':
|
||||
try {
|
||||
if (std::stoi(optarg) > 0) {
|
||||
// Debug(1) << "Setting debug level to " << optarg;
|
||||
Debug::set_debug_level(std::stoi(optarg));
|
||||
}
|
||||
}
|
||||
|
@ -41,29 +39,6 @@ int main(int argc, char** argv) {
|
|||
case 'u':
|
||||
update = 1;
|
||||
break;
|
||||
// case 's':
|
||||
// try {
|
||||
// if (std::stoi(optarg) > 0) {
|
||||
// heat_stamp_size = std::stoi(optarg);
|
||||
// }
|
||||
// }
|
||||
// catch (...) {
|
||||
// std::cout << "Option \"-s\" requires a valid number as an argument\n";
|
||||
// std::exit(EXIT_FAILURE);
|
||||
// }
|
||||
// break;
|
||||
// case 'm':
|
||||
// heat_map = optarg;
|
||||
// break;
|
||||
// case 'e':
|
||||
// heat_exp = 1;
|
||||
// break;
|
||||
// case 'L':
|
||||
// show_list = 1;
|
||||
// break;
|
||||
// case 'T':
|
||||
// show_dt = 1;
|
||||
// break;
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
|
|
54
ocdb.cpp
54
ocdb.cpp
|
@ -38,12 +38,14 @@ bool OCdb::request(std::string req) {
|
|||
|
||||
res = sqlite3_prepare_v2(db, req.c_str(), req.length() + 1, &stmt, NULL);
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << "Request \"" << req << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << req << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
res = sqlite3_step(stmt);
|
||||
if (res != SQLITE_DONE) {
|
||||
Debug(1) << "Request \"" << req << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << req << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
@ -107,31 +109,25 @@ bool OCdb::parse_item(json j) {
|
|||
// Debug(1) << "Code change " << j["object_key"]["code"] << " -> " << j["data"]["code"] <<'\n';
|
||||
// }
|
||||
update_cache(j);
|
||||
}
|
||||
else if (j.count("change_type") > 0 && j["change_type"] == "delete") {
|
||||
} else if (j.count("change_type") > 0 && j["change_type"] == "delete") {
|
||||
Debug(2) << "Deleting cache " << j["object_key"]["code"].get<std::string>() << ".\n";
|
||||
std::string sql = "DELETE FROM caches WHERE code='" + j["object_key"]["code"].get<std::string>() + "';";
|
||||
request(sql);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Debug(1) << "Incorrect change type: " << j["change_type"] << ".\n";
|
||||
}
|
||||
}
|
||||
else if (j.count("object_type") > 0 && j["object_type"] == "log") {
|
||||
} else if (j.count("object_type") > 0 && j["object_type"] == "log") {
|
||||
if (j["change_type"] == "replace") {
|
||||
Debug(3) << "Updating log " << j["object_key"]["uuid"] << ".\n";
|
||||
update_log(j);
|
||||
}
|
||||
else if (j.count("change_type") > 0 && j["change_type"] == "delete") {
|
||||
} else if (j.count("change_type") > 0 && j["change_type"] == "delete") {
|
||||
Debug(2) << "Deleting log " << j["object_key"]["uuid"] << ".\n";
|
||||
std::string sql = "DELETE FROM logs WHERE uuid='" + j["object_key"]["uuid"].get<std::string>() + "';";
|
||||
request(sql);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Debug(1) << "Incorrect change type: " << j["change_type"] << ".\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Debug(1) << "Incorrect object type: " << j["object_type"] << ".\n";
|
||||
}
|
||||
return 1;
|
||||
|
@ -194,7 +190,8 @@ bool OCdb::update_cache(json j) {
|
|||
|
||||
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
int n = 1;
|
||||
|
@ -206,7 +203,8 @@ bool OCdb::update_cache(json j) {
|
|||
}
|
||||
res = sqlite3_step(stmt);
|
||||
if (res != SQLITE_DONE) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
@ -247,7 +245,8 @@ bool OCdb::update_log(json j) {
|
|||
|
||||
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
int n = 1;
|
||||
|
@ -256,7 +255,8 @@ bool OCdb::update_log(json j) {
|
|||
}
|
||||
res = sqlite3_step(stmt);
|
||||
if (res != SQLITE_DONE) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
@ -269,12 +269,14 @@ bool OCdb::read_revision() {
|
|||
|
||||
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
res = sqlite3_step(stmt);
|
||||
if (res != SQLITE_ROW) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
return 0;
|
||||
}
|
||||
revision = sqlite3_column_int(stmt, 0);
|
||||
|
@ -293,7 +295,8 @@ Caches OCdb::get_user_caches_not_found(std::string uuid) {
|
|||
|
||||
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
throw 0;
|
||||
}
|
||||
sqlite3_bind_text(stmt, 1, uuid.c_str(), -1, nullptr);
|
||||
|
@ -307,7 +310,8 @@ Caches OCdb::get_user_caches_not_found(std::string uuid) {
|
|||
}
|
||||
|
||||
if (res != SQLITE_DONE) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
throw 0;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
@ -323,7 +327,8 @@ Caches OCdb::get_user_caches(std::string uuid, __attribute__((unused)) int count
|
|||
|
||||
res = sqlite3_prepare_v2(db, sql.c_str(), sql.length() + 1, &stmt, NULL);
|
||||
if (res != SQLITE_OK) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
throw 0;
|
||||
}
|
||||
sqlite3_bind_text(stmt, 1, uuid.c_str(), -1, nullptr);
|
||||
|
@ -344,7 +349,8 @@ Caches OCdb::get_user_caches(std::string uuid, __attribute__((unused)) int count
|
|||
}
|
||||
|
||||
if (res != SQLITE_DONE) {
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n" << sqlite3_errmsg(db);
|
||||
Debug(1) << "Request \"" << sql << "\" failed:\n"
|
||||
<< sqlite3_errmsg(db);
|
||||
throw 0;
|
||||
}
|
||||
//sqlite3_finalize(stmt);
|
||||
|
|
1
ocdb.h
1
ocdb.h
|
@ -24,6 +24,7 @@ private:
|
|||
bool update_cache(json j);
|
||||
bool update_log(json j);
|
||||
bool read_revision();
|
||||
|
||||
public:
|
||||
OCdb(std::string db_file);
|
||||
~OCdb();
|
||||
|
|
Ładowanie…
Reference in New Issue