5#include "../SqlColumnTypeDefinitions.hpp"
12#if !defined(SQL_SS_TIME2)
18#define SQL_SS_TIME2 (-154)
20struct SQL_SS_TIME2_STRUCT
29 sizeof(SQL_SS_TIME2_STRUCT) == 12,
30 "SQL_SS_TIME2_STRUCT size must be padded 12 bytes, as per ODBC extension spec."
45 using native_type = std::chrono::hh_mm_ss<std::chrono::microseconds>;
47#if defined(SQL_SS_TIME2)
68 constexpr ~
SqlTime() noexcept = default;
79 return value().to_duration().count() == other.value().to_duration().count();
85 return !(*
this == other);
95 LIGHTWEIGHT_FORCE_INLINE
constexpr SqlTime(std::chrono::hours hour,
96 std::chrono::minutes minute,
97 std::chrono::seconds second,
98 std::chrono::microseconds micros = {})
noexcept:
107 .hour = (SQLUSMALLINT)
value.hours().count(),
108 .minute = (SQLUSMALLINT)
value.minutes().count(),
109 .second = (SQLUSMALLINT)
value.seconds().count(),
110#if defined(SQL_SS_TIME2)
111 .fraction = (SQLUINTEGER)
value.subseconds().count(),
121 + std::chrono::minutes { (unsigned)
value.minute }
122 + std::chrono::seconds { (unsigned)
value.second }
123#if defined(SQL_SS_TIME2)
124 + std::chrono::microseconds {
value.fraction }
133struct SqlDataBinder<SqlTime>
135 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Time {};
137 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
139 SqlTime
const& value,
140 SqlDataBinderCallback& )
noexcept
142 return SQLBindParameter(
143 stmt, column, SQL_PARAM_INPUT, SQL_C_TYPE_TIME, SQL_TYPE_TIME, 0, 0, (SQLPOINTER) &value.sqlValue, 0,
nullptr);
146 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN OutputColumn(
147 SQLHSTMT stmt, SQLUSMALLINT column, SqlTime* result, SQLLEN* indicator, SqlDataBinderCallback& )
noexcept
149 return SQLBindCol(stmt, column, SQL_C_TYPE_TIME, &result->sqlValue,
sizeof(result->sqlValue), indicator);
152 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN GetColumn(
153 SQLHSTMT stmt, SQLUSMALLINT column, SqlTime* result, SQLLEN* indicator, SqlDataBinderCallback
const& )
noexcept
155 return SQLGetData(stmt, column, SQL_C_TYPE_TIME, &result->sqlValue,
sizeof(result->sqlValue), indicator);
158 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(SqlTime
const& value)
noexcept
160 return std::format(
"{:02}:{:02}:{:02}.{:06}",
162 value.sqlValue.minute,
163 value.sqlValue.second,
164 value.sqlValue.fraction);
171struct std::formatter<Lightweight::SqlTime>: std::formatter<std::string>
173 auto format(
Lightweight::SqlTime const& value, std::format_context& ctx)
const -> std::format_context::iterator
175 return std::formatter<std::string>::format(std::format(
"{:02}:{:02}:{:02}.{:06}",
177 value.sqlValue.minute,
178 value.sqlValue.second,
179 value.sqlValue.fraction),
static LIGHTWEIGHT_FORCE_INLINE constexpr sql_type ConvertToSqlValue(native_type value) noexcept
Converts a native time value to the SQL representation.
constexpr SqlTime() noexcept=default
Default constructor.
std::chrono::hh_mm_ss< std::chrono::microseconds > native_type
The native C++ type for time representation.
SQL_SS_TIME2_STRUCT sql_type
The SQL type used for ODBC binding.
LIGHTWEIGHT_FORCE_INLINE constexpr bool operator!=(SqlTime const &other) const noexcept
Inequality comparison operator.
LIGHTWEIGHT_FORCE_INLINE constexpr bool operator==(SqlTime const &other) const noexcept
Equality comparison operator.
sql_type sqlValue
The underlying SQL value for ODBC binding.
LIGHTWEIGHT_FORCE_INLINE constexpr SqlTime(native_type value) noexcept
Constructs a SqlTime from a native time value.
LIGHTWEIGHT_FORCE_INLINE constexpr native_type value() const noexcept
Returns the native time value.
static LIGHTWEIGHT_FORCE_INLINE constexpr native_type ConvertToNative(sql_type const &value) noexcept
Converts a SQL time value to the native representation.
LIGHTWEIGHT_FORCE_INLINE constexpr SqlTime(std::chrono::hours hour, std::chrono::minutes minute, std::chrono::seconds second, std::chrono::microseconds micros={}) noexcept
Constructs a SqlTime from hours, minutes, seconds, and optional microseconds.