6#include "SqlDataBinder.hpp"
10#include <source_location>
33 LIGHTWEIGHT_API
virtual ~SqlLogger() =
default;
49 virtual void OnWarning(std::string_view
const& message) = 0;
52 virtual void OnError(SqlError errorCode, std::source_location sourceLocation = std::source_location::current()) = 0;
56 std::source_location sourceLocation = std::source_location::current()) = 0;
80 virtual void OnPrepare(std::string_view
const& query) = 0;
86 if (_supportsBindLogging)
88 using value_type = std::remove_cvref_t<T>;
89 if constexpr (SqlDataBinderSupportsInspect<value_type>)
91 OnBind(name, std::string(SqlDataBinder<value_type>::Inspect(std::forward<T>(value))));
97 virtual void OnBind(std::string_view
const& name, std::string value) = 0;
100 virtual void OnExecute(std::string_view
const& query) = 0;
134 bool _supportsBindLogging = false;
140 void OnWarning(std::string_view
const& )
override {}
141 void OnError(SqlError , std::source_location )
override {}
150 void OnPrepare(std::string_view
const& )
override {}
151 void OnBind(std::string_view
const& , std::string )
override {}
152 void OnExecute(std::string_view
const& )
override {}
172 _tag { std::move(tag) }
Represents a connection to a SQL database.
Represents a logger for SQL operations.
static LIGHTWEIGHT_API void SetLogger(SqlLogger &logger)
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 OnFetchRow()=0
Invoked when a row is fetched.
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.
std::function< void(std::string)> MessageWriter
Type definition for a function that writes messages.
virtual void OnExecute(std::string_view const &query)=0
Invoked when a prepared query is executed.
static LIGHTWEIGHT_API Null & NullLogger() noexcept
Retrieves a null logger that does nothing.
virtual void OnPrepare(std::string_view const &query)=0
Invoked when a query is prepared.
static LIGHTWEIGHT_API SqlLogger & GetLogger()
Retrieves the currently configured logger.
virtual void OnError(SqlError errorCode, std::source_location sourceLocation=std::source_location::current())=0
Invoked on ODBC SQL error occurred.
void OnBindInputParameter(std::string_view const &name, T &&value)
Invoked when an input parameter is bound.
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.
virtual void OnBind(std::string_view const &name, std::string value)=0
Invoked when an input parameter is bound, by name.
virtual void OnConnectionIdle(SqlConnection const &connection)=0
Invoked when a connection is idle.
SupportBindLogging
Mandates the support for logging bind operations.
static LIGHTWEIGHT_API SqlLogger & StandardLogger()
Retrieves a logger that logs to standard output.
LIGHTWEIGHT_API SqlLogger(SupportBindLogging supportBindLogging, MessageWriter writer={})
static LIGHTWEIGHT_API SqlLogger & TraceLogger()
Retrieves a logger that logs to the trace logger.
virtual void OnFetchEnd()=0
Invoked when fetching is done.
virtual void OnConnectionOpened(SqlConnection const &connection)=0
Invoked when a connection is opened.
virtual void OnExecuteBatch()=0
Invoked when a batch of queries is executed.
virtual void OnExecuteDirect(std::string_view const &query)=0
Invoked when a direct query is executed.
virtual void OnConnectionClosed(SqlConnection const &connection)=0
Invoked when a connection is closed.
virtual void OnConnectionReuse(SqlConnection const &connection)=0
Invoked when a connection is reused.
LIGHTWEIGHT_API void SetLoggingSink(MessageWriter writer={})
virtual void OnWarning(std::string_view const &message)=0
Invoked on a warning.
Represents an ODBC SQL error.
Represents a value that can be any of the supported SQL data types.