fix
This commit is contained in:
		| @@ -53,7 +53,7 @@ private: | |||||||
|  |  | ||||||
| private: | private: | ||||||
|   app_config &config_; |   app_config &config_; | ||||||
|   db::db3_t db_; |   utils::db::sqlite::db3_t db_; | ||||||
|  |  | ||||||
| private: | private: | ||||||
|   i_file_manager *fm_ = nullptr; |   i_file_manager *fm_ = nullptr; | ||||||
|   | |||||||
| @@ -194,12 +194,12 @@ auto encrypt_provider::get_api_path_from_source( | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   try { |   try { | ||||||
|     auto result = db::db_select{*db_, file_table} |     auto result = utils::db::sqlite::db_select{*db_, file_table} | ||||||
|                       .column("data") |                       .column("data") | ||||||
|                       .where("source_path") |                       .where("source_path") | ||||||
|                       .equals(source_path) |                       .equals(source_path) | ||||||
|                       .go(); |                       .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()) { |     if (result.get_row(row) && row.has_value()) { | ||||||
|       api_path = row->get_column("data") |       api_path = row->get_column("data") | ||||||
|                      .get_value_as_json() |                      .get_value_as_json() | ||||||
| @@ -208,7 +208,7 @@ auto encrypt_provider::get_api_path_from_source( | |||||||
|       return api_error::success; |       return api_error::success; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     result = db::db_select{*db_, directory_table} |     result = utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                  .column("api_path") |                  .column("api_path") | ||||||
|                  .where("source_path") |                  .where("source_path") | ||||||
|                  .equals(source_path) |                  .equals(source_path) | ||||||
| @@ -273,12 +273,13 @@ auto encrypt_provider::get_directory_items( | |||||||
|             try { |             try { | ||||||
|               std::string current_api_path{}; |               std::string current_api_path{}; | ||||||
|               if (dir_entry->is_directory_item()) { |               if (dir_entry->is_directory_item()) { | ||||||
|                 auto result = db::db_select{*db_, directory_table} |                 auto result = | ||||||
|  |                     utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                         .column("api_path") |                         .column("api_path") | ||||||
|                         .where("source_path") |                         .where("source_path") | ||||||
|                         .equals(dir_entry->get_path()) |                         .equals(dir_entry->get_path()) | ||||||
|                         .go(); |                         .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()) { |                 if (result.get_row(row) && row.has_value()) { | ||||||
|                   current_api_path = |                   current_api_path = | ||||||
|                       row->get_column("api_path").get_value<std::string>(); |                       row->get_column("api_path").get_value<std::string>(); | ||||||
| @@ -287,7 +288,7 @@ auto encrypt_provider::get_directory_items( | |||||||
|                   process_directory_entry(*dir_entry.get(), cfg, |                   process_directory_entry(*dir_entry.get(), cfg, | ||||||
|                                           current_api_path); |                                           current_api_path); | ||||||
|  |  | ||||||
|                   result = db::db_select{*db_, directory_table} |                   result = utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                                .column("api_path") |                                .column("api_path") | ||||||
|                                .where("source_path") |                                .where("source_path") | ||||||
|                                .equals(dir_entry->get_path()) |                                .equals(dir_entry->get_path()) | ||||||
| @@ -302,12 +303,12 @@ auto encrypt_provider::get_directory_items( | |||||||
|                 } |                 } | ||||||
|               } else { |               } else { | ||||||
|                 std::string api_path_data{}; |                 std::string api_path_data{}; | ||||||
|                 auto result = db::db_select{*db_, file_table} |                 auto result = utils::db::sqlite::db_select{*db_, file_table} | ||||||
|                                   .column("data") |                                   .column("data") | ||||||
|                                   .where("source_path") |                                   .where("source_path") | ||||||
|                                   .equals(dir_entry->get_path()) |                                   .equals(dir_entry->get_path()) | ||||||
|                                   .go(); |                                   .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()) { |                 if (result.get_row(row) && row.has_value()) { | ||||||
|                   api_path_data = |                   api_path_data = | ||||||
|                       row->get_column("data").get_value<std::string>(); |                       row->get_column("data").get_value<std::string>(); | ||||||
| @@ -387,12 +388,12 @@ auto encrypt_provider::get_file(const std::string &api_path, | |||||||
|       return api_error::directory_exists; |       return api_error::directory_exists; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     auto result = db::db_select{*db_, source_table} |     auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                       .column("source_path") |                       .column("source_path") | ||||||
|                       .where("api_path") |                       .where("api_path") | ||||||
|                       .equals(api_path) |                       .equals(api_path) | ||||||
|                       .go(); |                       .go(); | ||||||
|     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())) { |     if (not(result.get_row(row) && row.has_value())) { | ||||||
|       return api_error::item_not_found; |       return api_error::item_not_found; | ||||||
|     } |     } | ||||||
| @@ -443,12 +444,12 @@ auto encrypt_provider::get_file_size( | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   try { |   try { | ||||||
|     auto result = db::db_select{*db_, source_table} |     auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                       .column("source_path") |                       .column("source_path") | ||||||
|                       .where("api_path") |                       .where("api_path") | ||||||
|                       .equals(api_path) |                       .equals(api_path) | ||||||
|                       .go(); |                       .go(); | ||||||
|     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())) { |     if (not(result.get_row(row) && row.has_value())) { | ||||||
|       return api_error::item_not_found; |       return api_error::item_not_found; | ||||||
|     } |     } | ||||||
| @@ -468,12 +469,12 @@ auto encrypt_provider::get_file_size( | |||||||
| auto encrypt_provider::get_filesystem_item( | auto encrypt_provider::get_filesystem_item( | ||||||
|     const std::string &api_path, bool directory, |     const std::string &api_path, bool directory, | ||||||
|     filesystem_item &fsi) const -> api_error { |     filesystem_item &fsi) const -> api_error { | ||||||
|   auto result = db::db_select{*db_, source_table} |   auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                     .column("source_path") |                     .column("source_path") | ||||||
|                     .where("api_path") |                     .where("api_path") | ||||||
|                     .equals(api_path) |                     .equals(api_path) | ||||||
|                     .go(); |                     .go(); | ||||||
|   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())) { |   if (not(result.get_row(row) && row.has_value())) { | ||||||
|     return api_error::item_not_found; |     return api_error::item_not_found; | ||||||
|   } |   } | ||||||
| @@ -481,7 +482,7 @@ auto encrypt_provider::get_filesystem_item( | |||||||
|   auto source_path = row->get_column("source_path").get_value<std::string>(); |   auto source_path = row->get_column("source_path").get_value<std::string>(); | ||||||
|  |  | ||||||
|   if (directory) { |   if (directory) { | ||||||
|     result = db::db_select{*db_, directory_table} |     result = utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                  .column("api_path") |                  .column("api_path") | ||||||
|                  .where("source_path") |                  .where("source_path") | ||||||
|                  .equals(source_path) |                  .equals(source_path) | ||||||
| @@ -500,7 +501,7 @@ auto encrypt_provider::get_filesystem_item( | |||||||
|     return api_error::success; |     return api_error::success; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   result = db::db_select{*db_, file_table} |   result = utils::db::sqlite::db_select{*db_, file_table} | ||||||
|                .column("data") |                .column("data") | ||||||
|                .where("source_path") |                .where("source_path") | ||||||
|                .equals(source_path) |                .equals(source_path) | ||||||
| @@ -586,12 +587,12 @@ auto encrypt_provider::get_item_meta(const std::string &api_path, | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   try { |   try { | ||||||
|     auto result = db::db_select{*db_, source_table} |     auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                       .column("source_path") |                       .column("source_path") | ||||||
|                       .where("api_path") |                       .where("api_path") | ||||||
|                       .equals(api_path) |                       .equals(api_path) | ||||||
|                       .go(); |                       .go(); | ||||||
|     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())) { |     if (not(result.get_row(row) && row.has_value())) { | ||||||
|       return api_error::item_not_found; |       return api_error::item_not_found; | ||||||
|     } |     } | ||||||
| @@ -635,10 +636,11 @@ auto encrypt_provider::get_total_drive_space() const -> std::uint64_t { | |||||||
| } | } | ||||||
|  |  | ||||||
| auto encrypt_provider::get_total_item_count() const -> std::uint64_t { | auto encrypt_provider::get_total_item_count() const -> std::uint64_t { | ||||||
|   auto result = |   auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|       db::db_select{*db_, source_table}.count("api_path", "count").go(); |                     .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()) { |   if (result.get_row(row) && row.has_value()) { | ||||||
|     return static_cast<std::uint64_t>( |     return static_cast<std::uint64_t>( | ||||||
|         row->get_column("count").get_value<std::int64_t>()); |         row->get_column("count").get_value<std::int64_t>()); | ||||||
| @@ -656,12 +658,12 @@ auto encrypt_provider::get_used_drive_space() const -> std::uint64_t { | |||||||
|  |  | ||||||
| auto encrypt_provider::is_directory(const std::string &api_path, | auto encrypt_provider::is_directory(const std::string &api_path, | ||||||
|                                     bool &exists) const -> api_error { |                                     bool &exists) const -> api_error { | ||||||
|   auto result = db::db_select{*db_, source_table} |   auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                     .column("source_path") |                     .column("source_path") | ||||||
|                     .where("api_path") |                     .where("api_path") | ||||||
|                     .equals(api_path) |                     .equals(api_path) | ||||||
|                     .go(); |                     .go(); | ||||||
|   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())) { |   if (not(result.get_row(row) && row.has_value())) { | ||||||
|     exists = false; |     exists = false; | ||||||
|     return api_error::success; |     return api_error::success; | ||||||
| @@ -677,12 +679,12 @@ auto encrypt_provider::is_directory(const std::string &api_path, | |||||||
|  |  | ||||||
| auto encrypt_provider::is_file(const std::string &api_path, | auto encrypt_provider::is_file(const std::string &api_path, | ||||||
|                                bool &exists) const -> api_error { |                                bool &exists) const -> api_error { | ||||||
|   auto result = db::db_select{*db_, source_table} |   auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                     .column("source_path") |                     .column("source_path") | ||||||
|                     .where("api_path") |                     .where("api_path") | ||||||
|                     .equals(api_path) |                     .equals(api_path) | ||||||
|                     .go(); |                     .go(); | ||||||
|   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())) { |   if (not(result.get_row(row) && row.has_value())) { | ||||||
|     exists = false; |     exists = false; | ||||||
|     return api_error::success; |     return api_error::success; | ||||||
| @@ -739,12 +741,12 @@ auto encrypt_provider::process_directory_entry( | |||||||
|       current_source_path = utils::path::combine(current_source_path, {part}); |       current_source_path = utils::path::combine(current_source_path, {part}); | ||||||
|  |  | ||||||
|       std::string current_api_path{}; |       std::string current_api_path{}; | ||||||
|       auto result = db::db_select{*db_, directory_table} |       auto result = utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                         .column("api_path") |                         .column("api_path") | ||||||
|                         .where("source_path") |                         .where("source_path") | ||||||
|                         .equals(current_source_path) |                         .equals(current_source_path) | ||||||
|                         .go(); |                         .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()) { |       if (result.get_row(row) && row.has_value()) { | ||||||
|         current_api_path = row->get_column("api_path").get_value<std::string>(); |         current_api_path = row->get_column("api_path").get_value<std::string>(); | ||||||
|       } |       } | ||||||
| @@ -753,12 +755,12 @@ auto encrypt_provider::process_directory_entry( | |||||||
|         current_api_path = utils::path::create_api_path( |         current_api_path = utils::path::create_api_path( | ||||||
|             current_encrypted_path + '/' + encrypted_parts.at(current_idx)); |             current_encrypted_path + '/' + encrypted_parts.at(current_idx)); | ||||||
|  |  | ||||||
|         auto ins_res = db::db_insert{*db_, directory_table} |         auto ins_res = utils::db::sqlite::db_insert{*db_, directory_table} | ||||||
|                            .column_value("source_path", current_source_path) |                            .column_value("source_path", current_source_path) | ||||||
|                            .column_value("api_path", current_api_path) |                            .column_value("api_path", current_api_path) | ||||||
|                            .go(); |                            .go(); | ||||||
|         // TODO handle error |         // TODO handle error | ||||||
|         ins_res = db::db_insert{*db_, source_table} |         ins_res = utils::db::sqlite::db_insert{*db_, source_table} | ||||||
|                       .column_value("api_path", current_api_path) |                       .column_value("api_path", current_api_path) | ||||||
|                       .column_value("source_path", current_source_path) |                       .column_value("source_path", current_source_path) | ||||||
|                       .go(); |                       .go(); | ||||||
| @@ -789,18 +791,18 @@ auto encrypt_provider::process_directory_entry( | |||||||
|         utils::path::get_relative_path(dir_entry.get_path(), cfg.path); |         utils::path::get_relative_path(dir_entry.get_path(), cfg.path); | ||||||
|  |  | ||||||
|     std::string api_path_data{}; |     std::string api_path_data{}; | ||||||
|     auto result = db::db_select{*db_, file_table} |     auto result = utils::db::sqlite::db_select{*db_, file_table} | ||||||
|                       .column("data") |                       .column("data") | ||||||
|                       .where("source_path") |                       .where("source_path") | ||||||
|                       .equals(dir_entry.get_path()) |                       .equals(dir_entry.get_path()) | ||||||
|                       .go(); |                       .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()) { |     if (result.get_row(row) && row.has_value()) { | ||||||
|       api_path_data = row->get_column("data").get_value<std::string>(); |       api_path_data = row->get_column("data").get_value<std::string>(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     std::string api_parent{}; |     std::string api_parent{}; | ||||||
|     result = db::db_select{*db_, directory_table} |     result = utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                  .column("api_path") |                  .column("api_path") | ||||||
|                  .where("source_path") |                  .where("source_path") | ||||||
|                  .equals(utils::path::get_parent_path(dir_entry.get_path())) |                  .equals(utils::path::get_parent_path(dir_entry.get_path())) | ||||||
| @@ -834,13 +836,13 @@ auto encrypt_provider::process_directory_entry( | |||||||
|                    .value_or(0U)), |                    .value_or(0U)), | ||||||
|           }, |           }, | ||||||
|       }; |       }; | ||||||
|       auto ins_res = db::db_insert{*db_, file_table} |       auto ins_res = utils::db::sqlite::db_insert{*db_, file_table} | ||||||
|                          .column_value("source_path", dir_entry.get_path()) |                          .column_value("source_path", dir_entry.get_path()) | ||||||
|                          .column_value("data", data.dump()) |                          .column_value("data", data.dump()) | ||||||
|                          .go(); |                          .go(); | ||||||
|       // TODO handle error |       // TODO handle error | ||||||
|  |  | ||||||
|       ins_res = db::db_insert{*db_, source_table} |       ins_res = utils::db::sqlite::db_insert{*db_, source_table} | ||||||
|                     .column_value("api_path", api_path) |                     .column_value("api_path", api_path) | ||||||
|                     .column_value("source_path", dir_entry.get_path()) |                     .column_value("source_path", dir_entry.get_path()) | ||||||
|                     .go(); |                     .go(); | ||||||
| @@ -865,12 +867,12 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path, | |||||||
|       static_cast<const char *>(__FUNCTION__), |       static_cast<const char *>(__FUNCTION__), | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   auto result = db::db_select{*db_, source_table} |   auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                     .column("source_path") |                     .column("source_path") | ||||||
|                     .where("api_path") |                     .where("api_path") | ||||||
|                     .equals(api_path) |                     .equals(api_path) | ||||||
|                     .go(); |                     .go(); | ||||||
|   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())) { |   if (not(result.get_row(row) && row.has_value())) { | ||||||
|     return api_error::item_not_found; |     return api_error::item_not_found; | ||||||
|   } |   } | ||||||
| @@ -880,7 +882,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path, | |||||||
|     return api_error::item_not_found; |     return api_error::item_not_found; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   result = db::db_select{*db_, file_table} |   result = utils::db::sqlite::db_select{*db_, file_table} | ||||||
|                .column("data") |                .column("data") | ||||||
|                .where("source_path") |                .where("source_path") | ||||||
|                .equals(source_path) |                .equals(source_path) | ||||||
| @@ -919,7 +921,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path, | |||||||
|  |  | ||||||
|     file_data["original_file_size"] = file_size; |     file_data["original_file_size"] = file_size; | ||||||
|     file_data["iv_list"] = iv_list; |     file_data["iv_list"] = iv_list; | ||||||
|     auto ins_res = db::db_insert{*db_, file_table} |     auto ins_res = utils::db::sqlite::db_insert{*db_, file_table} | ||||||
|                        .or_replace() |                        .or_replace() | ||||||
|                        .column_value("source_path", source_path) |                        .column_value("source_path", source_path) | ||||||
|                        .column_value("data", file_data.dump()) |                        .column_value("data", file_data.dump()) | ||||||
| @@ -974,11 +976,11 @@ void encrypt_provider::remove_deleted_files() { | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   std::vector<removed_item> removed_list{}; |   std::vector<removed_item> removed_list{}; | ||||||
|   std::vector<db::db_select::row> row_list{}; |   std::vector<utils::db::sqlite::db_select::row> row_list{}; | ||||||
|  |  | ||||||
|   auto result = db::db_select{*db_, source_table}.go(); |   auto result = utils::db::sqlite::db_select{*db_, source_table}.go(); | ||||||
|   while (result.has_row()) { |   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()) { |     if (result.get_row(row) && row.has_value()) { | ||||||
|       row_list.push_back(row.value()); |       row_list.push_back(row.value()); | ||||||
|     } |     } | ||||||
| @@ -988,7 +990,7 @@ void encrypt_provider::remove_deleted_files() { | |||||||
|     auto source_path = row.get_column("source_path").get_value<std::string>(); |     auto source_path = row.get_column("source_path").get_value<std::string>(); | ||||||
|     if (not utils::path::exists(source_path)) { |     if (not utils::path::exists(source_path)) { | ||||||
|       auto api_path = row.get_column("api_path").get_value<std::string>(); |       auto api_path = row.get_column("api_path").get_value<std::string>(); | ||||||
|       result = db::db_select{*db_, file_table} |       result = utils::db::sqlite::db_select{*db_, file_table} | ||||||
|                    .column("source_path") |                    .column("source_path") | ||||||
|                    .where("source_path") |                    .where("source_path") | ||||||
|                    .equals(source_path) |                    .equals(source_path) | ||||||
| @@ -1000,12 +1002,12 @@ void encrypt_provider::remove_deleted_files() { | |||||||
|  |  | ||||||
|   for (auto &&item : removed_list) { |   for (auto &&item : removed_list) { | ||||||
|     if (not item.directory) { |     if (not item.directory) { | ||||||
|       auto del_res = db::db_delete{*db_, source_table} |       auto del_res = utils::db::sqlite::db_delete{*db_, source_table} | ||||||
|                          .where("api_path") |                          .where("api_path") | ||||||
|                          .equals(item.api_path) |                          .equals(item.api_path) | ||||||
|                          .go(); |                          .go(); | ||||||
|       // TODO handle error |       // TODO handle error | ||||||
|       del_res = db::db_delete{*db_, file_table} |       del_res = utils::db::sqlite::db_delete{*db_, file_table} | ||||||
|                     .where("source_path") |                     .where("source_path") | ||||||
|                     .equals(item.source_path) |                     .equals(item.source_path) | ||||||
|                     .go(); |                     .go(); | ||||||
| @@ -1017,12 +1019,12 @@ void encrypt_provider::remove_deleted_files() { | |||||||
|  |  | ||||||
|   for (auto &&item : removed_list) { |   for (auto &&item : removed_list) { | ||||||
|     if (item.directory) { |     if (item.directory) { | ||||||
|       auto del_res = db::db_delete{*db_, source_table} |       auto del_res = utils::db::sqlite::db_delete{*db_, source_table} | ||||||
|                          .where("api_path") |                          .where("api_path") | ||||||
|                          .equals(item.api_path) |                          .equals(item.api_path) | ||||||
|                          .go(); |                          .go(); | ||||||
|       // TODO handle error |       // TODO handle error | ||||||
|       del_res = db::db_delete{*db_, directory_table} |       del_res = utils::db::sqlite::db_delete{*db_, directory_table} | ||||||
|                     .where("source_path") |                     .where("source_path") | ||||||
|                     .equals(item.source_path) |                     .equals(item.source_path) | ||||||
|                     .go(); |                     .go(); | ||||||
| @@ -1060,7 +1062,7 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/, | |||||||
|  |  | ||||||
|   for (auto &&create : sql_create_tables) { |   for (auto &&create : sql_create_tables) { | ||||||
|     std::string err; |     std::string err; | ||||||
|     if (not db::execute_sql(*db_, create.second, err)) { |     if (not utils::db::sqlite::execute_sql(*db_, create.second, err)) { | ||||||
|       utils::error::raise_error(function_name, "failed to create table|" + |       utils::error::raise_error(function_name, "failed to create table|" + | ||||||
|                                                    create.first + '|' + err); |                                                    create.first + '|' + err); | ||||||
|       db_.reset(); |       db_.reset(); | ||||||
| @@ -1068,21 +1070,21 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/, | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   db::set_journal_mode(*db_); |   utils::db::sqlite::set_journal_mode(*db_); | ||||||
|  |  | ||||||
|   const auto cfg = config_.get_encrypt_config(); |   const auto cfg = config_.get_encrypt_config(); | ||||||
|  |  | ||||||
|   std::string source_path; |   std::string source_path; | ||||||
|   auto result = db::db_select{*db_, source_table} |   auto result = utils::db::sqlite::db_select{*db_, source_table} | ||||||
|                     .column("source_path") |                     .column("source_path") | ||||||
|                     .where("api_path") |                     .where("api_path") | ||||||
|                     .equals("/") |                     .equals("/") | ||||||
|                     .go(); |                     .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()) { |   if (result.get_row(row) && row.has_value()) { | ||||||
|     source_path = row->get_column("source_path").get_value<std::string>(); |     source_path = row->get_column("source_path").get_value<std::string>(); | ||||||
|   } else { |   } else { | ||||||
|     auto ins_res = db::db_insert{*db_, source_table} |     auto ins_res = utils::db::sqlite::db_insert{*db_, source_table} | ||||||
|                        .column_value("api_path", "/") |                        .column_value("api_path", "/") | ||||||
|                        .column_value("source_path", cfg.path) |                        .column_value("source_path", cfg.path) | ||||||
|                        .go(); |                        .go(); | ||||||
| @@ -1090,13 +1092,13 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/, | |||||||
|     source_path = cfg.path; |     source_path = cfg.path; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   result = db::db_select{*db_, directory_table} |   result = utils::db::sqlite::db_select{*db_, directory_table} | ||||||
|                .column("api_path") |                .column("api_path") | ||||||
|                .where("source_path") |                .where("source_path") | ||||||
|                .equals(source_path) |                .equals(source_path) | ||||||
|                .go(); |                .go(); | ||||||
|   if (not result.has_row()) { |   if (not result.has_row()) { | ||||||
|     auto ins_res = db::db_insert{*db_, directory_table} |     auto ins_res = utils::db::sqlite::db_insert{*db_, directory_table} | ||||||
|                        .column_value("source_path", source_path) |                        .column_value("source_path", source_path) | ||||||
|                        .column_value("api_path", "/") |                        .column_value("api_path", "/") | ||||||
|                        .go(); |                        .go(); | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ namespace repertory { | |||||||
| class database_test : public ::testing::Test { | class database_test : public ::testing::Test { | ||||||
| public: | public: | ||||||
|   static console_consumer cs; |   static console_consumer cs; | ||||||
|   db::db3_t db3; |   utils::db::sqlite::db3_t db3; | ||||||
|  |  | ||||||
|   void SetUp() override { |   void SetUp() override { | ||||||
|     event_system::instance().start(); |     event_system::instance().start(); | ||||||
| @@ -54,7 +54,7 @@ public: | |||||||
| }; | }; | ||||||
|  |  | ||||||
| static void common_insert(sqlite3 &db, bool dump = false) { | static void common_insert(sqlite3 &db, bool dump = false) { | ||||||
|   auto query = db::db_insert{db, "table"} |   auto query = utils::db::sqlite::db_insert{db, "table"} | ||||||
|                    .column_value("column1", "test0") |                    .column_value("column1", "test0") | ||||||
|                    .column_value("column2", "test1"); |                    .column_value("column2", "test1"); | ||||||
|   if (dump) { |   if (dump) { | ||||||
| @@ -67,7 +67,7 @@ static void common_insert(sqlite3 &db, bool dump = false) { | |||||||
|  |  | ||||||
| static void common_select(sqlite3 &db, std::string value1, std::string value2, | static void common_select(sqlite3 &db, std::string value1, std::string value2, | ||||||
|                           bool dump = false) { |                           bool dump = false) { | ||||||
|   auto query = db::db_select{db, "table"}; |   auto query = utils::db::sqlite::db_select{db, "table"}; | ||||||
|   if (dump) { |   if (dump) { | ||||||
|     std::cout << query.dump() << std::endl; |     std::cout << query.dump() << std::endl; | ||||||
|   } |   } | ||||||
| @@ -78,7 +78,7 @@ static void common_select(sqlite3 &db, std::string value1, std::string value2, | |||||||
|  |  | ||||||
|   std::size_t row_count{}; |   std::size_t row_count{}; | ||||||
|   while (res.has_row()) { |   while (res.has_row()) { | ||||||
|     std::optional<db::db_select::row> row; |     std::optional<utils::db::sqlite::db_select::row> row; | ||||||
|     EXPECT_TRUE(res.get_row(row)); |     EXPECT_TRUE(res.get_row(row)); | ||||||
|     EXPECT_TRUE(row.has_value()); |     EXPECT_TRUE(row.has_value()); | ||||||
|     if (row.has_value()) { |     if (row.has_value()) { | ||||||
| @@ -104,7 +104,7 @@ static void common_select(sqlite3 &db, std::string value1, std::string value2, | |||||||
|  |  | ||||||
| static void common_delete(sqlite3 &db, bool dump = false) { | static void common_delete(sqlite3 &db, bool dump = false) { | ||||||
|   { |   { | ||||||
|     auto query = db::db_delete{db, "table"}; |     auto query = utils::db::sqlite::db_delete{db, "table"}; | ||||||
|     if (dump) { |     if (dump) { | ||||||
|       std::cout << query.dump() << std::endl; |       std::cout << query.dump() << std::endl; | ||||||
|     } |     } | ||||||
| @@ -114,7 +114,7 @@ static void common_delete(sqlite3 &db, bool dump = false) { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   { |   { | ||||||
|     auto query = db::db_select{db, "table"}; |     auto query = utils::db::sqlite::db_select{db, "table"}; | ||||||
|     auto res = query.go(); |     auto res = query.go(); | ||||||
|     EXPECT_TRUE(res.ok()); |     EXPECT_TRUE(res.ok()); | ||||||
|  |  | ||||||
| @@ -128,14 +128,14 @@ static void common_delete(sqlite3 &db, bool dump = false) { | |||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_delete_query) { | TEST_F(database_test, db_delete_query) { | ||||||
|   auto query = db::db_delete{*db3.get(), "table"}; |   auto query = utils::db::sqlite::db_delete{*db3.get(), "table"}; | ||||||
|   auto query_str = query.dump(); |   auto query_str = query.dump(); | ||||||
|   std::cout << query_str << std::endl; |   std::cout << query_str << std::endl; | ||||||
|   EXPECT_STREQ(R"(DELETE FROM "table";)", query_str.c_str()); |   EXPECT_STREQ(R"(DELETE FROM "table";)", query_str.c_str()); | ||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_delete_where_query) { | TEST_F(database_test, db_delete_where_query) { | ||||||
|   auto query = db::db_delete{*db3.get(), "table"} |   auto query = utils::db::sqlite::db_delete{*db3.get(), "table"} | ||||||
|                    .where("column1") |                    .where("column1") | ||||||
|                    .equals("test1") |                    .equals("test1") | ||||||
|                    .and_() |                    .and_() | ||||||
| @@ -148,7 +148,7 @@ TEST_F(database_test, db_delete_where_query) { | |||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_insert_query) { | TEST_F(database_test, db_insert_query) { | ||||||
|   auto query = db::db_insert{*db3.get(), "table"} |   auto query = utils::db::sqlite::db_insert{*db3.get(), "table"} | ||||||
|                    .column_value("column1", "test9") |                    .column_value("column1", "test9") | ||||||
|                    .column_value("column2", "test9"); |                    .column_value("column2", "test9"); | ||||||
|   auto query_str = query.dump(); |   auto query_str = query.dump(); | ||||||
| @@ -158,7 +158,7 @@ TEST_F(database_test, db_insert_query) { | |||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_insert_or_replace_query) { | TEST_F(database_test, db_insert_or_replace_query) { | ||||||
|   auto query = db::db_insert{*db3.get(), "table"} |   auto query = utils::db::sqlite::db_insert{*db3.get(), "table"} | ||||||
|                    .or_replace() |                    .or_replace() | ||||||
|                    .column_value("column1", "test1") |                    .column_value("column1", "test1") | ||||||
|                    .column_value("column2", "test2"); |                    .column_value("column2", "test2"); | ||||||
| @@ -170,14 +170,14 @@ TEST_F(database_test, db_insert_or_replace_query) { | |||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_select_query) { | TEST_F(database_test, db_select_query) { | ||||||
|   auto query = db::db_select{*db3.get(), "table"}; |   auto query = utils::db::sqlite::db_select{*db3.get(), "table"}; | ||||||
|   auto query_str = query.dump(); |   auto query_str = query.dump(); | ||||||
|   std::cout << query_str << std::endl; |   std::cout << query_str << std::endl; | ||||||
|   EXPECT_STREQ(R"(SELECT * FROM "table";)", query_str.c_str()); |   EXPECT_STREQ(R"(SELECT * FROM "table";)", query_str.c_str()); | ||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_select_where_query) { | TEST_F(database_test, db_select_where_query) { | ||||||
|   auto query = db::db_select{*db3.get(), "table"} |   auto query = utils::db::sqlite::db_select{*db3.get(), "table"} | ||||||
|                    .where("column1") |                    .where("column1") | ||||||
|                    .equals("test1") |                    .equals("test1") | ||||||
|                    .and_() |                    .and_() | ||||||
| @@ -191,7 +191,7 @@ TEST_F(database_test, db_select_where_query) { | |||||||
|  |  | ||||||
| TEST_F(database_test, db_select_where_with_group_query) { | TEST_F(database_test, db_select_where_with_group_query) { | ||||||
|   auto query = |   auto query = | ||||||
|       db::db_select{*db3.get(), "table"} |       utils::db::sqlite::db_select{*db3.get(), "table"} | ||||||
|           .group([](auto &grp) { |           .group([](auto &grp) { | ||||||
|             grp.where("column1").equals("a").or_().where("column1").equals("b"); |             grp.where("column1").equals("a").or_().where("column1").equals("b"); | ||||||
|           }) |           }) | ||||||
| @@ -211,7 +211,7 @@ TEST_F(database_test, db_select_where_with_group_query) { | |||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_select_columns_query) { | TEST_F(database_test, db_select_columns_query) { | ||||||
|   auto query = db::db_select{*db3.get(), "table"} |   auto query = utils::db::sqlite::db_select{*db3.get(), "table"} | ||||||
|                    .column("column1") |                    .column("column1") | ||||||
|                    .column("column2") |                    .column("column2") | ||||||
|                    .where("column1") |                    .where("column1") | ||||||
| @@ -227,7 +227,7 @@ TEST_F(database_test, db_select_columns_query) { | |||||||
| } | } | ||||||
|  |  | ||||||
| TEST_F(database_test, db_update_query) { | TEST_F(database_test, db_update_query) { | ||||||
|   auto query = db::db_update{*db3.get(), "table"} |   auto query = utils::db::sqlite::db_update{*db3.get(), "table"} | ||||||
|                    .column_value("column1", "moose") |                    .column_value("column1", "moose") | ||||||
|                    .where("column1") |                    .where("column1") | ||||||
|                    .equals("test1") |                    .equals("test1") | ||||||
| @@ -253,7 +253,7 @@ TEST_F(database_test, insert_update_delete) { | |||||||
|   common_insert(*db3.get()); |   common_insert(*db3.get()); | ||||||
|  |  | ||||||
|   { |   { | ||||||
|     auto query = db::db_update{*db3.get(), "table"} |     auto query = utils::db::sqlite::db_update{*db3.get(), "table"} | ||||||
|                      .column_value("column1", "moose") |                      .column_value("column1", "moose") | ||||||
|                      .where("column1") |                      .where("column1") | ||||||
|                      .equals("test0"); |                      .equals("test0"); | ||||||
| @@ -271,7 +271,7 @@ TEST_F(database_test, insert_or_replace_and_delete) { | |||||||
|   common_insert(*db3.get()); |   common_insert(*db3.get()); | ||||||
|  |  | ||||||
|   { |   { | ||||||
|     auto query = db::db_insert{*db3.get(), "table"} |     auto query = utils::db::sqlite::db_insert{*db3.get(), "table"} | ||||||
|                      .or_replace() |                      .or_replace() | ||||||
|                      .column_value("column1", "test0") |                      .column_value("column1", "test0") | ||||||
|                      .column_value("column2", "moose"); |                      .column_value("column2", "moose"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user