From 14ebdab0344acce3bc2fc7f7fa03f8251926ebbd Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 9 Oct 2024 10:27:51 -0500 Subject: [PATCH] fix --- .../repertory_test/src/database_test.cpp | 30 ++++++++++++++---- repertory/repertory_test/test_config/test.db3 | Bin 16384 -> 0 bytes support/src/utils/db/sqlite/db_delete.cpp | 7 +--- support/src/utils/db/sqlite/db_insert.cpp | 7 +--- support/src/utils/db/sqlite/db_select.cpp | 7 +--- support/src/utils/db/sqlite/db_update.cpp | 9 ------ 6 files changed, 26 insertions(+), 34 deletions(-) delete mode 100644 repertory/repertory_test/test_config/test.db3 diff --git a/repertory/repertory_test/src/database_test.cpp b/repertory/repertory_test/src/database_test.cpp index e55a9bad..2a649b16 100644 --- a/repertory/repertory_test/src/database_test.cpp +++ b/repertory/repertory_test/src/database_test.cpp @@ -37,14 +37,30 @@ public: void SetUp() override { event_system::instance().start(); - sqlite3 *db3_ptr{nullptr}; - auto res = sqlite3_open_v2( - utils::path::combine(test::get_test_input_dir(), {"test.db3"}).c_str(), - &db3_ptr, SQLITE_OPEN_READWRITE, nullptr); - ASSERT_EQ(SQLITE_OK, res); - ASSERT_TRUE(db3_ptr != nullptr); + { + sqlite3 *db3_ptr{nullptr}; + auto res = + sqlite3_open_v2(":memory:", &db3_ptr, SQLITE_OPEN_READWRITE, nullptr); + ASSERT_EQ(SQLITE_OK, res); + ASSERT_TRUE(db3_ptr != nullptr); + db3.reset(db3_ptr); + } - db3.reset(db3_ptr); + std::string sql{ + "CREATE TABLE [table] (column1 TEXT PRIMARY KEY UNIQUE " + "NOT NULL, column2 TEXT NOT NULL);", + }; + + db3_stmt_t db3_stmt; + { + sqlite3_stmt *stmt_ptr{}; + res = sqlite3_prepare_v2(db3_ptr, sql.c_str(), -1, &stmt_ptr, nullptr); + ASSERT_EQ(SQLITE_OK, res); + db3_stmt.reset(stmt_ptr); + } + + res = sqlite3_step(db3_stmt.get()); + ASSERT_EQ(SQLITE_DONE, res); } void TearDown() override { diff --git a/repertory/repertory_test/test_config/test.db3 b/repertory/repertory_test/test_config/test.db3 deleted file mode 100644 index 1f8fd12b0fd6201ed8092a1fa12c6efa10874945..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI%&q@M89Ki8e4J|>}+tTfamlPzhP9Z@Sdyvf1R>;$0xq{%jl`C}UBJ_H`fRE4< zbZlqWiVo>H_zvt0zxn&y&uy67PHP-`G76skK`6(ns0>4$i72Jg(YLd1ji}vQ$59g( z-M6iz)#2zpZ#Gq`uu_GUxipvCmN1S00tg_000IagfB*srAb`LY0rNw>T9&am2nY8Q zKa;g|aH0e6r%GLP?S^BE(>QP0Qi=ykQho>~bAMVB$G&sqrrW$~bo+8?_odfvc6zq7 zuN`UkTCJ)iGmny)U)`1H>^G}kHx~QxjBW00IagfB*sr OAb db_result { auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, - "failed to prepare|" + std::to_string(res) + '|' + - sqlite3_errstr(res) + '|' + query_str); return {context_, res}; } + context_->stmt.reset(stmt_ptr); for (std::int32_t idx = 0; @@ -69,9 +67,6 @@ auto db_delete::go() const -> db_result { }, context_->where_values.at(static_cast(idx))); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, - "failed to bind|" + std::to_string(res) + '|' + - sqlite3_errstr(res) + '|' + query_str); return {context_, res}; } } diff --git a/support/src/utils/db/sqlite/db_insert.cpp b/support/src/utils/db/sqlite/db_insert.cpp index 1978c7cc..b7d2b854 100644 --- a/support/src/utils/db/sqlite/db_insert.cpp +++ b/support/src/utils/db/sqlite/db_insert.cpp @@ -69,11 +69,9 @@ auto db_insert::go() const -> db_result { auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, "failed to prepare|" + - std::to_string(res) + '|' + - sqlite3_errstr(res)); return {context_, res}; } + context_->stmt.reset(stmt_ptr); for (std::int32_t idx = 0; @@ -90,9 +88,6 @@ auto db_insert::go() const -> db_result { }, std::next(context_->values.begin(), idx)->second); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, "failed to bind|" + - std::to_string(res) + '|' + - sqlite3_errstr(res)); return {context_, res}; } } diff --git a/support/src/utils/db/sqlite/db_select.cpp b/support/src/utils/db/sqlite/db_select.cpp index 2b34ee7e..3a40dcd1 100644 --- a/support/src/utils/db/sqlite/db_select.cpp +++ b/support/src/utils/db/sqlite/db_select.cpp @@ -94,11 +94,9 @@ auto db_select::go() const -> db_result { auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, - "failed to prepare|" + std::to_string(res) + '|' + - sqlite3_errstr(res) + '|' + query_str); return {context_, res}; } + context_->stmt.reset(stmt_ptr); for (std::int32_t idx = 0; @@ -115,9 +113,6 @@ auto db_select::go() const -> db_result { }, context_->where_values.at(static_cast(idx))); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, - "failed to bind|" + std::to_string(res) + '|' + - sqlite3_errstr(res) + '|' + query_str); return {context_, res}; } } diff --git a/support/src/utils/db/sqlite/db_update.cpp b/support/src/utils/db/sqlite/db_update.cpp index f939f60d..1cc316a9 100644 --- a/support/src/utils/db/sqlite/db_update.cpp +++ b/support/src/utils/db/sqlite/db_update.cpp @@ -73,9 +73,6 @@ auto db_update::go() const -> db_result { auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1, &stmt_ptr, nullptr); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, - "failed to prepare|" + std::to_string(res) + '|' + - sqlite3_errstr(res) + '|' + query_str); return {context_, res}; } context_->stmt.reset(stmt_ptr); @@ -94,9 +91,6 @@ auto db_update::go() const -> db_result { }, std::next(context_->column_values.begin(), idx)->second); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, "failed to bind|" + - std::to_string(res) + '|' + - sqlite3_errstr(res)); return {context_, res}; } } @@ -125,9 +119,6 @@ auto db_update::go() const -> db_result { }, context_->where_values.at(static_cast(idx))); if (res != SQLITE_OK) { - utils::error::raise_error(function_name, - "failed to bind|" + std::to_string(res) + '|' + - sqlite3_errstr(res) + '|' + query_str); return {context_, res}; } }