Add a DEBUG_SQL_QUERIES to log info about the executed SQL queries
fix #3324
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <biboumi.h>
|
||||
|
||||
#include <utils/optional_bool.hpp>
|
||||
#include <database/statement.hpp>
|
||||
#include <database/column.hpp>
|
||||
@@ -13,6 +15,20 @@ void actual_bind(Statement& statement, const std::string& value, int index);
|
||||
void actual_bind(Statement& statement, const std::size_t value, int index);
|
||||
void actual_bind(Statement& statement, const OptionalBool& value, int index);
|
||||
|
||||
#ifdef DEBUG_SQL_QUERIES
|
||||
#include <utils/scopetimer.hpp>
|
||||
|
||||
inline auto make_sql_timer()
|
||||
{
|
||||
return make_scope_timer([](const std::chrono::steady_clock::duration& elapsed)
|
||||
{
|
||||
const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed);
|
||||
const auto rest = elapsed - seconds;
|
||||
log_debug("Query executed in ", seconds.count(), ".", rest.count(), "s.");
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
struct Query
|
||||
{
|
||||
std::string body;
|
||||
@@ -22,6 +38,18 @@ struct Query
|
||||
Query(std::string str):
|
||||
body(std::move(str))
|
||||
{}
|
||||
|
||||
#ifdef DEBUG_SQL_QUERIES
|
||||
auto log_and_time()
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << this->body << "; ";
|
||||
for (const auto& param: this->params)
|
||||
os << "'" << param << "' ";
|
||||
log_debug("SQL QUERY: ", os.str());
|
||||
return make_sql_timer();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename ColumnType>
|
||||
@@ -58,3 +86,4 @@ operator<<(Query& query, const Integer& i)
|
||||
actual_add_param(query, i);
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user