From eb6341882d6b13d88aa6decd70d42292fe199e35 Mon Sep 17 00:00:00 2001 From: alice <58637860+alicealys@users.noreply.github.com> Date: Tue, 28 Jul 2026 02:53:12 +0200 Subject: [PATCH] mysql fix --- src/component/mysql.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/component/mysql.cpp b/src/component/mysql.cpp index a20a4f5..a1f2ae0 100644 --- a/src/component/mysql.cpp +++ b/src/component/mysql.cpp @@ -223,7 +223,7 @@ namespace mysql } catch (const std::exception& e) { - printf("%s\n", e.what()); + printf("^1MySQL ERROR: %s\n", e.what()); task->completed = true; } }); @@ -285,10 +285,10 @@ namespace mysql } template - void bind_statement_args(MYSQL_BIND* binds, std::size_t& bind_count, const T& args) + MYSQL_BIND* bind_statement_args(const T& args, std::size_t& bind_count) { bind_count = args.size(); - binds = utils::memory::allocate_array(bind_count); + const auto binds = utils::memory::allocate_array(bind_count); for (auto i = 0u; i < args.size(); i++) { @@ -327,6 +327,8 @@ namespace mysql } } } + + return binds; } void cleanup_connections() @@ -495,11 +497,11 @@ namespace mysql { if (values.size() > 0 && values[0].is()) { - bind_statement_args(binds, bind_count, values[0].as()); + binds = bind_statement_args(values[0].as(), bind_count); } else { - bind_statement_args(binds, bind_count, values); + binds = bind_statement_args(values, bind_count); } } catch (const std::exception& e) @@ -510,10 +512,7 @@ namespace mysql return create_mysql_query([=](database_t& db) { - const auto _0 = gsl::finally([&] - { - free_binds(); - }); + const auto _0 = gsl::finally(free_binds); mysql_result_t result{}; @@ -521,7 +520,7 @@ namespace mysql const auto stmt = mysql_stmt_init(handle); if (mysql_stmt_prepare(stmt, query.data(), query.size()) != 0 || - (binds != nullptr && mysql_stmt_bind_param(stmt, binds)) != 0 || + (binds != nullptr && mysql_stmt_bind_param(stmt, binds) != 0) || mysql_stmt_execute(stmt) != 0) { result.error = mysql_stmt_error(stmt);