updated build system
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
@@ -34,25 +34,30 @@ void sqlite3_deleter::operator()(sqlite3 *db3) const {
|
||||
return;
|
||||
}
|
||||
|
||||
utils::error::handle_error(function_name, "closing database handle");
|
||||
std::string err_msg;
|
||||
if (not execute_sql(*db3, "VACUUM;", err_msg)) {
|
||||
utils::error::handle_error(function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to vacuum database",
|
||||
err_msg,
|
||||
}));
|
||||
}
|
||||
|
||||
if (not utils::retry_action(
|
||||
[&db3]() -> bool {
|
||||
auto res = sqlite3_close_v2(db3);
|
||||
if (res == SQLITE_OK) {
|
||||
return true;
|
||||
}
|
||||
if (not utils::retry_action([&db3]() -> bool {
|
||||
auto res = sqlite3_close_v2(db3);
|
||||
if (res == SQLITE_OK) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto &&err_str = sqlite3_errstr(res);
|
||||
utils::error::handle_error(
|
||||
function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to close database",
|
||||
(err_str == nullptr ? std::to_string(res) : err_str),
|
||||
}));
|
||||
return false;
|
||||
},
|
||||
60U)) {
|
||||
auto &&err_str = sqlite3_errstr(res);
|
||||
utils::error::handle_error(
|
||||
function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to close database",
|
||||
(err_str == nullptr ? std::to_string(res) : err_str),
|
||||
}));
|
||||
return false;
|
||||
})) {
|
||||
repertory::utils::error::handle_error(function_name,
|
||||
"failed to close database");
|
||||
}
|
||||
@@ -71,8 +76,50 @@ auto db_column::get_value_as_json() const -> nlohmann::json {
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_JSON)
|
||||
|
||||
auto execute_sql(sqlite3 &db3, const std::string &sql, std::string &err)
|
||||
-> bool {
|
||||
auto create_db(std::string db_path,
|
||||
const std::map<std::string, std::string> &sql_create_tables)
|
||||
-> db3_t {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
sqlite3 *db_ptr{nullptr};
|
||||
auto db_res =
|
||||
sqlite3_open_v2(db_path.c_str(), &db_ptr,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
|
||||
if (db_res != SQLITE_OK) {
|
||||
const auto *msg = sqlite3_errstr(db_res);
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to open db",
|
||||
db_path,
|
||||
(msg == nullptr ? std::to_string(db_res) : msg),
|
||||
});
|
||||
}
|
||||
|
||||
auto db3 = db3_t{
|
||||
db_ptr,
|
||||
sqlite3_deleter(),
|
||||
};
|
||||
|
||||
for (auto &&create_item : sql_create_tables) {
|
||||
std::string err_msg;
|
||||
if (not sqlite::execute_sql(*db3, create_item.second, err_msg)) {
|
||||
db3.reset();
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
err_msg,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
set_journal_mode(*db3);
|
||||
|
||||
return db3;
|
||||
}
|
||||
|
||||
auto execute_sql(sqlite3 &db3, const std::string &sql,
|
||||
std::string &err) -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
char *err_msg{nullptr};
|
||||
auto res = sqlite3_exec(&db3, sql.c_str(), nullptr, nullptr, &err_msg);
|
||||
if (err_msg != nullptr) {
|
||||
@@ -85,15 +132,20 @@ auto execute_sql(sqlite3 &db3, const std::string &sql, std::string &err)
|
||||
return true;
|
||||
}
|
||||
|
||||
err = "failed to execute sql|" + sql + "|" + std::to_string(res) + '|' +
|
||||
(err.empty() ? sqlite3_errstr(res) : err);
|
||||
err = utils::error::create_error_message({
|
||||
function_name,
|
||||
"failed to execute sql",
|
||||
err,
|
||||
sql,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_journal_mode(sqlite3 &db3) {
|
||||
sqlite3_exec(&db3,
|
||||
"PRAGMA journal_mode = WAL;PRAGMA synchronous = NORMAL;PRAGMA "
|
||||
"auto_vacuum = FULL;",
|
||||
"auto_vacuum = NONE;",
|
||||
nullptr, nullptr, nullptr);
|
||||
}
|
||||
} // namespace repertory::utils::db::sqlite
|
||||
|
Reference in New Issue
Block a user