5#include "../SqlColumnTypeDefinitions.hpp"
13template <
typename T, SQLSMALLINT TheCType, SQLINTEGER TheSqlType, auto TheColumnType>
14struct SqlSimpleDataBinder
16 static constexpr SqlColumnTypeDefinition ColumnType = TheColumnType;
18 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
21 SqlDataBinderCallback& )
noexcept
23 return SQLBindParameter(stmt, column, SQL_PARAM_INPUT, TheCType, TheSqlType, 0, 0, (SQLPOINTER) &value, 0,
nullptr);
31 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN BatchInputParameter(SQLHSTMT stmt,
35 SqlDataBinderCallback& ,
36 SQLLEN* indicators =
nullptr) noexcept
38 return SQLBindParameter(
39 stmt, column, SQL_PARAM_INPUT, TheCType, TheSqlType, 0, 0, (SQLPOINTER) values,
sizeof(T), indicators);
42 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN OutputColumn(
43 SQLHSTMT stmt, SQLUSMALLINT column, T* result, SQLLEN* indicator, SqlDataBinderCallback& )
noexcept
45 return SQLBindCol(stmt, column, TheCType, result, 0, indicator);
48 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN
49 GetColumn(SQLHSTMT stmt, SQLUSMALLINT column, T* result, SQLLEN* indicator, SqlDataBinderCallback
const& )
noexcept
51 return SQLGetData(stmt, column, TheCType, result, 0, indicator);
54 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(T value)
56 return std::to_string(value);
60template <
typename Int64Type, SQLSMALLINT TheCType>
61struct Int64DataBinderHelper
63 static constexpr SqlColumnTypeDefinition ColumnType = SqlColumnTypeDefinitions::Bigint {};
65 static LIGHTWEIGHT_API SQLRETURN InputParameter(SQLHSTMT stmt,
67 Int64Type
const& value,
68 SqlDataBinderCallback& cb)
noexcept;
70 static LIGHTWEIGHT_API SQLRETURN BatchInputParameter(SQLHSTMT stmt,
72 Int64Type
const* values,
74 SqlDataBinderCallback& cb,
75 SQLLEN* indicators =
nullptr) noexcept;
77 static LIGHTWEIGHT_API SQLRETURN OutputColumn(
78 SQLHSTMT stmt, SQLUSMALLINT column, Int64Type* result, SQLLEN* indicator, SqlDataBinderCallback& cb) noexcept;
80 static LIGHTWEIGHT_API SQLRETURN GetColumn(
81 SQLHSTMT stmt, SQLUSMALLINT column, Int64Type* result, SQLLEN* indicator, SqlDataBinderCallback const& cb) noexcept;
83 static LIGHTWEIGHT_FORCE_INLINE std::
string Inspect(Int64Type value)
85 return std::to_string(value);
90template <>
struct SqlDataBinder<bool>: SqlSimpleDataBinder<bool, SQL_BIT, SQL_BIT, SqlColumnTypeDefinitions::Bool {}> {};
91template <>
struct SqlDataBinder<char>: SqlSimpleDataBinder<char, SQL_C_CHAR, SQL_CHAR, SqlColumnTypeDefinitions::Char {}> {};
92template <>
struct SqlDataBinder<int8_t>: SqlSimpleDataBinder<int8_t, SQL_C_STINYINT, SQL_TINYINT, SqlColumnTypeDefinitions::Tinyint {}> {};
93template <>
struct SqlDataBinder<uint8_t>: SqlSimpleDataBinder<uint8_t, SQL_C_UTINYINT, SQL_TINYINT, SqlColumnTypeDefinitions::Tinyint {}> {};
94template <>
struct SqlDataBinder<int16_t>: SqlSimpleDataBinder<int16_t, SQL_C_SSHORT, SQL_SMALLINT, SqlColumnTypeDefinitions::Smallint {}> {};
95template <>
struct SqlDataBinder<uint16_t>: SqlSimpleDataBinder<uint16_t, SQL_C_USHORT, SQL_SMALLINT, SqlColumnTypeDefinitions::Smallint {}> {};
96template <>
struct SqlDataBinder<int32_t>: SqlSimpleDataBinder<int32_t, SQL_C_SLONG, SQL_INTEGER, SqlColumnTypeDefinitions::Integer {}> {};
97template <>
struct SqlDataBinder<uint32_t>: SqlSimpleDataBinder<uint32_t, SQL_C_ULONG, SQL_INTEGER, SqlColumnTypeDefinitions::Integer {}> {};
98template <>
struct SqlDataBinder<int64_t>: Int64DataBinderHelper<int64_t, SQL_C_SBIGINT> {};
99template <>
struct SqlDataBinder<uint64_t>: Int64DataBinderHelper<uint64_t, SQL_C_UBIGINT> {};
101template <>
struct SqlDataBinder<float>: SqlSimpleDataBinder<float, SQL_C_FLOAT, SQL_REAL, SqlColumnTypeDefinitions::Real {}> {};
102template <>
struct SqlDataBinder<double>: SqlSimpleDataBinder<double, SQL_C_DOUBLE, SQL_DOUBLE, SqlColumnTypeDefinitions::Real {}> {};
103#if !defined(_WIN32) && !defined(__APPLE__)
104template <>
struct SqlDataBinder<long long>: Int64DataBinderHelper<long long, SQL_C_SBIGINT> {};
105template <>
struct SqlDataBinder<unsigned long long>: Int64DataBinderHelper<unsigned long long, SQL_C_UBIGINT> {};
107#if defined(__APPLE__)
110template <>
struct SqlDataBinder<std::size_t>: SqlSimpleDataBinder<std::size_t, SQL_C_UBIGINT, SQL_BIGINT, SqlColumnTypeDefinitions::Bigint {}> {};
117 requires detail::IsAnyOf<T, bool, char, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t,
119#if !defined(_WIN32) && !defined(__APPLE__)
120 ,
long long,
unsigned long long
122#if defined(__APPLE__)
126inline constexpr bool SqlIsNativeRowBindableValue<T> =
true;