diff --git a/support/include/utils/db/sqlite/db_common.hpp b/support/include/utils/db/sqlite/db_common.hpp index 5b395709..0124fa1b 100644 --- a/support/include/utils/db/sqlite/db_common.hpp +++ b/support/include/utils/db/sqlite/db_common.hpp @@ -39,8 +39,6 @@ using db3_t = std::unique_ptr; struct sqlite3_statement_deleter { void operator()(sqlite3_stmt *stmt) const { if (stmt != nullptr) { - std::cout << "freeing stmt" << std::endl; - sqlite3_reset(stmt); sqlite3_finalize(stmt); } } @@ -181,6 +179,8 @@ template struct db_result final { } } + ~db_result() { context_->clear(); } + private: std::shared_ptr context_; mutable std::int32_t res_; diff --git a/support/include/utils/db/sqlite/db_delete.hpp b/support/include/utils/db/sqlite/db_delete.hpp index 9cf8984f..3f67183a 100644 --- a/support/include/utils/db/sqlite/db_delete.hpp +++ b/support/include/utils/db/sqlite/db_delete.hpp @@ -37,6 +37,11 @@ public: std::optional where; std::vector where_values; + + void clear() { + where.reset(); + where_values.clear(); + } }; using row = db_row; diff --git a/support/include/utils/db/sqlite/db_insert.hpp b/support/include/utils/db/sqlite/db_insert.hpp index 95770249..2452f731 100644 --- a/support/include/utils/db/sqlite/db_insert.hpp +++ b/support/include/utils/db/sqlite/db_insert.hpp @@ -34,6 +34,8 @@ public: bool or_replace{false}; std::map values{}; + + void clear() { values.clear(); } }; using row = db_row; diff --git a/support/include/utils/db/sqlite/db_select.hpp b/support/include/utils/db/sqlite/db_select.hpp index e5fd47d9..8bc3c494 100644 --- a/support/include/utils/db/sqlite/db_select.hpp +++ b/support/include/utils/db/sqlite/db_select.hpp @@ -33,14 +33,24 @@ public: struct context final : db_context_t { context(sqlite3 &db3_, std::string table_name_) : db_context_t(db3_, table_name_) {} + using w_t = db_where_with_limit_t; - std::vector columns{}; - std::map count_columns{}; + std::vector columns; + std::map count_columns; std::optional limit; std::optional> order_by; std::optional where; std::vector where_values; + + void clear() { + columns.clear(); + count_columns.clear(); + limit.reset(); + order_by.reset(); + where.reset(); + where_values.clear(); + } }; using row = db_row; diff --git a/support/include/utils/db/sqlite/db_update.hpp b/support/include/utils/db/sqlite/db_update.hpp index b44279ca..902029b6 100644 --- a/support/include/utils/db/sqlite/db_update.hpp +++ b/support/include/utils/db/sqlite/db_update.hpp @@ -35,11 +35,19 @@ public: : db_context_t(db3_, table_name_) {} using w_t = db_where_with_limit_t; - std::map column_values{}; + std::map column_values; std::optional limit; std::optional> order_by; std::optional where; std::vector where_values; + + void clear() { + column_values.clear(); + limit.reset(); + order_by.reset(); + where.reset(); + where_values.clear(); + } }; using row = db_row; diff --git a/support/src/utils/db/sqlite/db_insert.cpp b/support/src/utils/db/sqlite/db_insert.cpp index 4170eca8..bce5ac6a 100644 --- a/support/src/utils/db/sqlite/db_insert.cpp +++ b/support/src/utils/db/sqlite/db_insert.cpp @@ -60,10 +60,6 @@ auto db_insert::dump() const -> std::string { } auto db_insert::go() const -> db_result { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - sqlite3_stmt *stmt_ptr{nullptr}; auto query_str = dump(); auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,