fix
This commit is contained in:
parent
6a97ad664b
commit
9adec02640
@ -452,7 +452,7 @@ private:
|
||||
i_provider &provider_;
|
||||
|
||||
private:
|
||||
db::db3_t db_{nullptr};
|
||||
utils::db::sqlite::db3_t db_{nullptr};
|
||||
std::uint64_t next_handle_{0U};
|
||||
mutable std::recursive_mutex open_file_mtx_;
|
||||
std::unordered_map<std::string, std::shared_ptr<i_closeable_open_file>>
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
auto operator=(meta_db &&) -> meta_db & = delete;
|
||||
|
||||
private:
|
||||
db::db3_t db_;
|
||||
utils::db::sqlite::db3_t db_;
|
||||
constexpr static const auto table_name = "meta";
|
||||
|
||||
private:
|
||||
|
@ -119,13 +119,13 @@ file_manager::file_manager(app_config &config, i_provider &provider)
|
||||
|
||||
for (auto &&create_item : sql_create_tables) {
|
||||
std::string err;
|
||||
if (not db::execute_sql(*db_, create_item.second, err)) {
|
||||
if (not utils::db::sqlite::execute_sql(*db_, create_item.second, err)) {
|
||||
db_.reset();
|
||||
throw startup_exception(err);
|
||||
}
|
||||
}
|
||||
|
||||
db::set_journal_mode(*db_);
|
||||
utils::db::sqlite::set_journal_mode(*db_);
|
||||
|
||||
E_SUBSCRIBE_EXACT(file_upload_completed,
|
||||
[this](const file_upload_completed &completed) {
|
||||
@ -354,10 +354,10 @@ auto file_manager::get_stored_downloads() const -> std::vector<json> {
|
||||
|
||||
std::vector<json> ret;
|
||||
if (not provider_.is_direct_only()) {
|
||||
auto result = db::db_select{*db_.get(), resume_table}.go();
|
||||
auto result = utils::db::sqlite::db_select{*db_.get(), resume_table}.go();
|
||||
while (result.has_row()) {
|
||||
try {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (not result.get_row(row)) {
|
||||
continue;
|
||||
}
|
||||
@ -390,12 +390,12 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
|
||||
source_path = upload_lookup_.at(from_api_path)->get_source_path();
|
||||
}
|
||||
} else {
|
||||
auto result = db::db_select{*db_.get(), upload_table}
|
||||
auto result = utils::db::sqlite::db_select{*db_.get(), upload_table}
|
||||
.column("source_path")
|
||||
.where("api_path")
|
||||
.equals(from_api_path)
|
||||
.go();
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
should_upload = result.get_row(row) && row.has_value();
|
||||
if (should_upload && source_path.empty()) {
|
||||
source_path = row->get_column("source_path").get_value<std::string>();
|
||||
@ -438,7 +438,7 @@ auto file_manager::is_processing(const std::string &api_path) const -> bool {
|
||||
}
|
||||
upload_lock.unlock();
|
||||
|
||||
db::db_select query{*db_.get(), upload_table};
|
||||
utils::db::sqlite::db_select query{*db_.get(), upload_table};
|
||||
if (query.where("api_path").equals(api_path).go().has_row()) {
|
||||
return true;
|
||||
};
|
||||
@ -521,7 +521,7 @@ void file_manager::queue_upload(const std::string &api_path,
|
||||
remove_upload(api_path, true);
|
||||
|
||||
auto result =
|
||||
db::db_insert{*db_.get(), upload_table}
|
||||
utils::db::sqlite::db_insert{*db_.get(), upload_table}
|
||||
.or_replace()
|
||||
.column_value("api_path", api_path)
|
||||
.column_value("date_time",
|
||||
@ -559,7 +559,7 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
||||
|
||||
remove_upload(api_path);
|
||||
|
||||
auto result = db::db_delete{*db_.get(), resume_table}
|
||||
auto result = utils::db::sqlite::db_delete{*db_.get(), resume_table}
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
@ -585,7 +585,7 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
||||
|
||||
void file_manager::remove_resume(const std::string &api_path,
|
||||
const std::string &source_path) {
|
||||
auto result = db::db_delete{*db_.get(), resume_table}
|
||||
auto result = utils::db::sqlite::db_delete{*db_.get(), resume_table}
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
@ -613,7 +613,7 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
|
||||
lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
}
|
||||
|
||||
auto result = db::db_delete{*db_.get(), upload_table}
|
||||
auto result = utils::db::sqlite::db_delete{*db_.get(), upload_table}
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
@ -623,7 +623,7 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
|
||||
"failed to remove from upload table");
|
||||
}
|
||||
|
||||
result = db::db_delete{*db_.get(), upload_active_table}
|
||||
result = utils::db::sqlite::db_delete{*db_.get(), upload_active_table}
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
@ -820,10 +820,11 @@ void file_manager::start() {
|
||||
|
||||
std::vector<active_item> active_items{};
|
||||
|
||||
auto result = db::db_select{*db_.get(), upload_active_table}.go();
|
||||
auto result =
|
||||
utils::db::sqlite::db_select{*db_.get(), upload_active_table}.go();
|
||||
while (result.has_row()) {
|
||||
try {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
active_items.emplace_back(active_item{
|
||||
row->get_column("api_path").get_value<std::string>(),
|
||||
@ -840,14 +841,14 @@ void file_manager::start() {
|
||||
}
|
||||
active_items.clear();
|
||||
|
||||
result = db::db_select{*db_.get(), resume_table}.go();
|
||||
result = utils::db::sqlite::db_select{*db_.get(), resume_table}.go();
|
||||
if (not result.ok()) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (result.has_row()) {
|
||||
try {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return;
|
||||
}
|
||||
@ -957,7 +958,7 @@ void file_manager::store_resume(const i_open_file &file) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = db::db_insert{*db_.get(), resume_table}
|
||||
auto result = utils::db::sqlite::db_insert{*db_.get(), resume_table}
|
||||
.or_replace()
|
||||
.column_value("api_path", file.get_api_path())
|
||||
.column_value("data", create_resume_entry(file).dump())
|
||||
@ -992,7 +993,7 @@ void file_manager::swap_renamed_items(std::string from_api_path,
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = db::db_update{*db_.get(), resume_table}
|
||||
auto result = utils::db::sqlite::db_update{*db_.get(), resume_table}
|
||||
.column_value("api_path", to_api_path)
|
||||
.where("api_path")
|
||||
.equals(from_api_path)
|
||||
@ -1014,7 +1015,8 @@ void file_manager::upload_completed(const file_upload_completed &evt) {
|
||||
if (not utils::string::to_bool(evt.get_cancelled().get<std::string>())) {
|
||||
auto err = api_error_from_string(evt.get_result().get<std::string>());
|
||||
if (err == api_error::success) {
|
||||
auto result = db::db_delete{*db_.get(), upload_active_table}
|
||||
auto result =
|
||||
utils::db::sqlite::db_delete{*db_.get(), upload_active_table}
|
||||
.where("api_path")
|
||||
.equals(evt.get_api_path().get<std::string>())
|
||||
.go();
|
||||
@ -1062,12 +1064,12 @@ void file_manager::upload_handler() {
|
||||
}
|
||||
|
||||
if (upload_lookup_.size() < config_.get_max_upload_count()) {
|
||||
auto result = db::db_select{*db_.get(), upload_table}
|
||||
auto result = utils::db::sqlite::db_select{*db_.get(), upload_table}
|
||||
.order_by("api_path", true)
|
||||
.limit(1)
|
||||
.go();
|
||||
try {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
auto api_path = row->get_column("api_path").get_value<std::string>();
|
||||
auto source_path =
|
||||
@ -1088,12 +1090,14 @@ void file_manager::upload_handler() {
|
||||
|
||||
upload_lookup_[fsi.api_path] =
|
||||
std::make_unique<upload>(fsi, provider_);
|
||||
auto del_res = db::db_delete{*db_.get(), upload_table}
|
||||
auto del_res =
|
||||
utils::db::sqlite::db_delete{*db_.get(), upload_table}
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
if (del_res.ok()) {
|
||||
auto ins_res = db::db_insert{*db_.get(), upload_active_table}
|
||||
auto ins_res =
|
||||
utils::db::sqlite::db_insert{*db_.get(), upload_active_table}
|
||||
.column_value("api_path", api_path)
|
||||
.column_value("source_path", source_path)
|
||||
.go();
|
||||
|
@ -60,28 +60,28 @@ meta_db::meta_db(const app_config &cfg) {
|
||||
"source_path TEXT"
|
||||
");";
|
||||
std::string err;
|
||||
if (not db::execute_sql(*db_, create, err)) {
|
||||
if (not utils::db::sqlite::execute_sql(*db_, create, err)) {
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to create db|" + db_path + '|' + err);
|
||||
db_.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
db::set_journal_mode(*db_);
|
||||
utils::db::sqlite::set_journal_mode(*db_);
|
||||
}
|
||||
|
||||
meta_db::~meta_db() { db_.reset(); }
|
||||
|
||||
auto meta_db::get_api_path(const std::string &source_path,
|
||||
std::string &api_path) -> api_error {
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
.column("api_path")
|
||||
.where("source_path")
|
||||
.equals(source_path)
|
||||
.limit(1)
|
||||
.go();
|
||||
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
api_path = row->get_column("api_path").get_value<std::string>();
|
||||
return api_error::success;
|
||||
@ -93,9 +93,10 @@ auto meta_db::get_api_path(const std::string &source_path,
|
||||
auto meta_db::get_api_path_list() -> std::vector<std::string> {
|
||||
std::vector<std::string> ret{};
|
||||
|
||||
auto result = db::db_select{*db_, table_name}.column("api_path").go();
|
||||
auto result =
|
||||
utils::db::sqlite::db_select{*db_, table_name}.column("api_path").go();
|
||||
while (result.has_row()) {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret.push_back(row->get_column("api_path").get_value<std::string>());
|
||||
}
|
||||
@ -110,7 +111,7 @@ auto meta_db::get_item_meta(const std::string &api_path,
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
.column("*")
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
@ -121,7 +122,7 @@ auto meta_db::get_item_meta(const std::string &api_path,
|
||||
}
|
||||
|
||||
try {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
meta = json::parse(row->get_column("data").get_value<std::string>())
|
||||
.get<api_meta_map>();
|
||||
@ -150,7 +151,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
.column("*")
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
@ -161,7 +162,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
}
|
||||
|
||||
try {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
value =
|
||||
key == META_SOURCE
|
||||
@ -195,13 +196,13 @@ auto meta_db::get_pinned_files() const -> std::vector<std::string> {
|
||||
std::vector<std::string> ret{};
|
||||
|
||||
try {
|
||||
auto result = db::db_select{*db_, table_name}
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
.column("api_path")
|
||||
.where("pinned")
|
||||
.equals(1)
|
||||
.go();
|
||||
while (result.has_row()) {
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret.emplace_back(row->get_column("api_path").get_value<std::string>());
|
||||
}
|
||||
@ -221,10 +222,11 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
|
||||
std::uint64_t ret{};
|
||||
|
||||
try {
|
||||
auto result =
|
||||
db::db_select{*db_, table_name}.count("api_path", "count").go();
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
.count("api_path", "count")
|
||||
.go();
|
||||
|
||||
std::optional<db::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret = static_cast<std::uint64_t>(
|
||||
row->get_column("count").get_value<std::int64_t>());
|
||||
@ -242,8 +244,10 @@ void meta_db::remove_api_path(const std::string &api_path) {
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto result =
|
||||
db::db_delete{*db_, table_name}.where("api_path").equals(api_path).go();
|
||||
auto result = utils::db::sqlite::db_delete{*db_, table_name}
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
if (not result.ok()) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, api_path, result.get_error(), "failed to remove meta");
|
||||
@ -307,7 +311,7 @@ auto meta_db::update_item_meta(const std::string &api_path,
|
||||
meta.erase(META_PINNED);
|
||||
meta.erase(META_SOURCE);
|
||||
|
||||
auto result = db::db_insert{*db_, table_name}
|
||||
auto result = utils::db::sqlite::db_insert{*db_, table_name}
|
||||
.or_replace()
|
||||
.column_value("api_path", api_path)
|
||||
.column_value("data", nlohmann::json(meta).dump())
|
||||
|
@ -111,7 +111,7 @@ struct db_comp_next_limit_t final {
|
||||
|
||||
using wn_t = db_where_next_limit_t<db_comp_next_limit_t, ctx_t, op_t, w_t>;
|
||||
|
||||
[[nodiscard]] auto create(std::string operation, db::db_types_t value) {
|
||||
[[nodiscard]] auto create(std::string operation, db_types_t value) {
|
||||
owner->actions.emplace_back(db_comp_data_t{
|
||||
column_name,
|
||||
operation,
|
||||
@ -125,19 +125,19 @@ struct db_comp_next_limit_t final {
|
||||
};
|
||||
}
|
||||
|
||||
auto equals(db::db_types_t value) -> wn_t { return create("=", value); };
|
||||
auto equals(db_types_t value) -> wn_t { return create("=", value); };
|
||||
|
||||
auto gt(db::db_types_t value) -> wn_t { return create(">", value); }
|
||||
auto gt(db_types_t value) -> wn_t { return create(">", value); }
|
||||
|
||||
auto gte(db::db_types_t value) -> wn_t { return create(">=", value); }
|
||||
auto gte(db_types_t value) -> wn_t { return create(">=", value); }
|
||||
|
||||
auto like(db::db_types_t value) -> wn_t { return create("LIKE", value); }
|
||||
auto like(db_types_t value) -> wn_t { return create("LIKE", value); }
|
||||
|
||||
auto lt(db::db_types_t value) -> wn_t { return create("<", value); }
|
||||
auto lt(db_types_t value) -> wn_t { return create("<", value); }
|
||||
|
||||
auto lte(db::db_types_t value) -> wn_t { return create("<=", value); }
|
||||
auto lte(db_types_t value) -> wn_t { return create("<=", value); }
|
||||
|
||||
auto not_equals(db::db_types_t value) -> wn_t { return create("!=", value); };
|
||||
auto not_equals(db_types_t value) -> wn_t { return create("!=", value); };
|
||||
};
|
||||
|
||||
template <typename ctx_t, typename op_t> struct db_where_with_limit_t final {
|
||||
|
@ -95,7 +95,7 @@ struct db_comp_next_t final {
|
||||
|
||||
using wn_t = db_where_next_t<db_comp_next_t, ctx_t, op_t, w_t>;
|
||||
|
||||
[[nodiscard]] auto create(std::string operation, db::db_types_t value) {
|
||||
[[nodiscard]] auto create(std::string operation, db_types_t value) {
|
||||
owner->actions.emplace_back(db_comp_data_t{
|
||||
column_name,
|
||||
operation,
|
||||
@ -109,19 +109,19 @@ struct db_comp_next_t final {
|
||||
};
|
||||
}
|
||||
|
||||
auto equals(db::db_types_t value) -> wn_t { return create("=", value); };
|
||||
auto equals(db_types_t value) -> wn_t { return create("=", value); };
|
||||
|
||||
auto gt(db::db_types_t value) -> wn_t { return create(">", value); }
|
||||
auto gt(db_types_t value) -> wn_t { return create(">", value); }
|
||||
|
||||
auto gte(db::db_types_t value) -> wn_t { return create(">=", value); }
|
||||
auto gte(db_types_t value) -> wn_t { return create(">=", value); }
|
||||
|
||||
auto like(db::db_types_t value) -> wn_t { return create("LIKE", value); }
|
||||
auto like(db_types_t value) -> wn_t { return create("LIKE", value); }
|
||||
|
||||
auto lt(db::db_types_t value) -> wn_t { return create("<", value); }
|
||||
auto lt(db_types_t value) -> wn_t { return create("<", value); }
|
||||
|
||||
auto lte(db::db_types_t value) -> wn_t { return create("<=", value); }
|
||||
auto lte(db_types_t value) -> wn_t { return create("<=", value); }
|
||||
|
||||
auto not_equals(db::db_types_t value) -> wn_t { return create("!=", value); };
|
||||
auto not_equals(db_types_t value) -> wn_t { return create("!=", value); };
|
||||
};
|
||||
|
||||
template <typename ctx_t, typename op_t> struct db_where_t final {
|
||||
|
Loading…
x
Reference in New Issue
Block a user