mirror of
https://github.com/alicealys/t5-gsc-utils.git
synced 2026-07-28 10:40:36 +00:00
small fix
This commit is contained in:
+29
-24
@@ -338,6 +338,21 @@ namespace mysql
|
||||
connection.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void free_statement_binds(MYSQL_BIND* binds, const std::size_t bind_count)
|
||||
{
|
||||
if (binds == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < bind_count; i++)
|
||||
{
|
||||
utils::memory::free(binds[i].buffer);
|
||||
}
|
||||
|
||||
utils::memory::free(binds);
|
||||
}
|
||||
}
|
||||
|
||||
utils::concurrency::container<sql::connection_config>& get_config()
|
||||
@@ -476,22 +491,7 @@ namespace mysql
|
||||
gsc::function::add("mysql::prepared_statement", [](const std::string& query, const scripting::variadic_args& values)
|
||||
{
|
||||
MYSQL_BIND* binds = nullptr;
|
||||
size_t bind_count = 0;
|
||||
|
||||
const auto free_binds = [=]
|
||||
{
|
||||
if (binds == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < bind_count; i++)
|
||||
{
|
||||
utils::memory::free(binds[i].buffer);
|
||||
}
|
||||
|
||||
utils::memory::free(binds);
|
||||
};
|
||||
auto bind_count = 0u;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -503,16 +503,13 @@ namespace mysql
|
||||
{
|
||||
binds = bind_statement_args(values, bind_count);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
free_binds();
|
||||
throw e;
|
||||
}
|
||||
|
||||
return create_mysql_query([=](database_t& db)
|
||||
const auto handle = create_mysql_query([binds, bind_count, query](database_t& db)
|
||||
{
|
||||
const auto _0 = gsl::finally(free_binds);
|
||||
const auto _0 = gsl::finally([=]
|
||||
{
|
||||
free_statement_binds(binds, bind_count);
|
||||
});
|
||||
|
||||
mysql_result_t result{};
|
||||
|
||||
@@ -532,6 +529,14 @@ namespace mysql
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
return handle;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
free_statement_binds(binds, bind_count);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user