6#include "SqlDataBinder.hpp"
10#include <source_location>
36 LIGHTWEIGHT_API
virtual ~SqlLogger() =
default;
52 virtual void OnWarning(std::string_view
const& message) = 0;
55 virtual void OnError(SqlError errorCode, std::source_location sourceLocation = std::source_location::current()) = 0;
59 std::source_location sourceLocation = std::source_location::current()) = 0;
83 virtual void OnPrepare(std::string_view
const& query) = 0;
89 if (_supportsBindLogging)
91 using value_type = std::remove_cvref_t<T>;
92 if constexpr (SqlDataBinderSupportsInspect<value_type>)
94 OnBind(name, std::string(SqlDataBinder<value_type>::Inspect(std::forward<T>(value))));
100 virtual void OnBind(std::string_view
const& name, std::string value) = 0;
103 virtual void OnExecute(std::string_view
const& query) = 0;
137 bool _supportsBindLogging = false;
143 void OnWarning(std::string_view
const& )
override {}
144 void OnError(SqlError , std::source_location )
override {}
153 void OnPrepare(std::string_view
const& )
override {}
154 void OnBind(std::string_view
const& , std::string )
override {}
155 void OnExecute(std::string_view
const& )
override {}
175 _tag { std::move(tag) }
177 SqlLogger::GetLogger().OnScopedTimerStart(_tag);
182 SqlLogger::GetLogger().OnScopedTimerStop(_tag);
Represents a connection to a SQL database.
Represents a logger for SQL operations.
virtual void OnExecuteDirect(std::string_view const &query)=0
Invoked when a direct query is executed.
virtual void OnExecute(std::string_view const &query)=0
Invoked when a prepared query is executed.
virtual void OnError(SqlError errorCode, std::source_location sourceLocation=std::source_location::current())=0
Invoked on ODBC SQL error occurred.
static LIGHTWEIGHT_API Null & NullLogger() noexcept
Retrieves a null logger that does nothing.
static LIGHTWEIGHT_API SqlLogger & GetLogger()
Retrieves the currently configured logger.
virtual void OnFetchEnd()=0
Invoked when fetching is done.
static LIGHTWEIGHT_API SqlLogger & TraceLogger()
Retrieves a logger that logs to the trace logger.
static LIGHTWEIGHT_API void SetLogger(SqlLogger &logger)
virtual void OnError(SqlErrorInfo const &errorInfo, std::source_location sourceLocation=std::source_location::current())=0
Invoked an ODBC SQL error occurred, with extended error information.
LIGHTWEIGHT_API void SetLoggingSink(MessageWriter writer={})
virtual void OnBind(std::string_view const &name, std::string value)=0
Invoked when an input parameter is bound, by name.
virtual void OnConnectionReuse(SqlConnection const &connection)=0
Invoked when a connection is reused.
static LIGHTWEIGHT_API SqlLogger & StandardLogger()
Retrieves a logger that logs to standard output.
virtual void OnPrepare(std::string_view const &query)=0
Invoked when a query is prepared.
virtual void OnExecuteBatch()=0
Invoked when a batch of queries is executed.
void OnBindInputParameter(std::string_view const &name, T &&value)
Invoked when an input parameter is bound.
std::function< void(std::string)> MessageWriter
Type definition for a function that writes messages.
virtual void OnConnectionClosed(SqlConnection const &connection)=0
Invoked when a connection is closed.
SupportBindLogging
Mandates the support for logging bind operations.
virtual void OnScopedTimerStart(std::string const &tag)=0
Invoked when a scoped code region needs to be timed and logged. The region starts with this call.
virtual void OnConnectionIdle(SqlConnection const &connection)=0
Invoked when a connection is idle.
virtual void OnScopedTimerStop(std::string const &tag)=0
Invoked when a scoped code region needs to be timed and logged. The region ends with this call.
virtual void OnWarning(std::string_view const &message)=0
Invoked on a warning.
virtual void OnFetchRow()=0
Invoked when a row is fetched.
virtual void OnConnectionOpened(SqlConnection const &connection)=0
Invoked when a connection is opened.
LIGHTWEIGHT_API SqlLogger(SupportBindLogging supportBindLogging, MessageWriter writer={})
Represents an ODBC SQL error.