5#include "../SqlColumnTypeDefinitions.hpp"
17template <
typename T, SQLSMALLINT TheCType, SQLINTEGER TheSqlType, auto TheColumnType>
18struct SqlSimpleDataBinder
20 static constexpr SqlColumnTypeDefinition ColumnType = TheColumnType;
22 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
25 SqlDataBinderCallback& )
noexcept
27 return SQLBindParameter(stmt, column, SQL_PARAM_INPUT, TheCType, TheSqlType, 0, 0, (SQLPOINTER) &value, 0,
nullptr);
35 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN BatchInputParameter(SQLHSTMT stmt,
39 SqlDataBinderCallback& ,
40 SQLLEN* indicators =
nullptr) noexcept
42 return SQLBindParameter(
43 stmt, column, SQL_PARAM_INPUT, TheCType, TheSqlType, 0, 0, (SQLPOINTER) values,
sizeof(T), indicators);
46 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN OutputColumn(
47 SQLHSTMT stmt, SQLUSMALLINT column, T* result, SQLLEN* indicator, SqlDataBinderCallback& )
noexcept
49 return SQLBindCol(stmt, column, TheCType, result, 0, indicator);
52 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN
53 GetColumn(SQLHSTMT stmt, SQLUSMALLINT column, T* result, SQLLEN* indicator, SqlDataBinderCallback
const& )
noexcept
55 return SQLGetData(stmt, column, TheCType, result, 0, indicator);
58 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(T value)
60 return std::to_string(value);
64template <
typename Int64Type, SQLSMALLINT TheCType>
65struct Int64DataBinderHelper
67 static constexpr SqlColumnTypeDefinition ColumnType = SqlColumnTypeDefinitions::Bigint {};
69 static LIGHTWEIGHT_API SQLRETURN InputParameter(SQLHSTMT stmt,
71 Int64Type
const& value,
72 SqlDataBinderCallback& cb)
noexcept;
74 static LIGHTWEIGHT_API SQLRETURN BatchInputParameter(SQLHSTMT stmt,
76 Int64Type
const* values,
78 SqlDataBinderCallback& cb,
79 SQLLEN* indicators =
nullptr) noexcept;
81 static LIGHTWEIGHT_API SQLRETURN OutputColumn(
82 SQLHSTMT stmt, SQLUSMALLINT column, Int64Type* result, SQLLEN* indicator, SqlDataBinderCallback& cb) noexcept;
84 static LIGHTWEIGHT_API SQLRETURN GetColumn(
85 SQLHSTMT stmt, SQLUSMALLINT column, Int64Type* result, SQLLEN* indicator, SqlDataBinderCallback const& cb) noexcept;
87 static LIGHTWEIGHT_FORCE_INLINE std::
string Inspect(Int64Type value)
89 return std::to_string(value);
104struct SqlDataBinder<char>
107 static constexpr SqlColumnTypeDefinition ColumnType = SqlColumnTypeDefinitions::Char { 1 };
121 auto*
const indicator = cb.ProvideInputIndicator();
122 *indicator = CharLength;
123 return SQLBindParameter(
124 stmt, column, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, ColumnSize, 0, (SQLPOINTER) &value, 0, indicator);
142 SQLLEN* indicators =
nullptr) noexcept
147 std::ranges::fill(std::span { indicators, rowCount }, CharLength);
149 return SQLBindParameter(stmt,
173 SQLHSTMT stmt, SQLUSMALLINT column,
char* result, SQLLEN* indicator,
SqlDataBinderCallback& cb)
noexcept
175 auto buffer = std::make_shared<Buffer>();
176 auto const sqlReturn = SQLBindCol(stmt, column, SQL_C_CHAR, buffer->data(), BufferSize, indicator);
177 cb.PlanPostProcessOutputColumn([buffer, result, indicator]() {
178 if (*indicator != SQL_NULL_DATA)
179 *result = buffer->front();
192 SQLHSTMT stmt, SQLUSMALLINT column,
char* result, SQLLEN* indicator,
SqlDataBinderCallback const& )
noexcept
194 auto buffer = Buffer {};
195 auto const sqlReturn = SQLGetData(stmt, column, SQL_C_CHAR, buffer.data(), BufferSize, indicator);
196 if (SQL_SUCCEEDED(sqlReturn) && *indicator != SQL_NULL_DATA)
197 *result = buffer.front();
203 static LIGHTWEIGHT_FORCE_INLINE std::string
Inspect(
char value)
210 using Buffer = std::array<char, 2>;
211 static constexpr SQLLEN CharLength = 1;
212 static constexpr SQLULEN ColumnSize = 1;
213 static constexpr SQLLEN BufferSize =
sizeof(Buffer);
217template <>
struct SqlDataBinder<bool>: SqlSimpleDataBinder<bool, SQL_BIT, SQL_BIT, SqlColumnTypeDefinitions::Bool {}> {};
218template <>
struct SqlDataBinder<int8_t>: SqlSimpleDataBinder<int8_t, SQL_C_STINYINT, SQL_TINYINT, SqlColumnTypeDefinitions::Tinyint {}> {};
219template <>
struct SqlDataBinder<uint8_t>: SqlSimpleDataBinder<uint8_t, SQL_C_UTINYINT, SQL_TINYINT, SqlColumnTypeDefinitions::Tinyint {}> {};
220template <>
struct SqlDataBinder<int16_t>: SqlSimpleDataBinder<int16_t, SQL_C_SSHORT, SQL_SMALLINT, SqlColumnTypeDefinitions::Smallint {}> {};
221template <>
struct SqlDataBinder<uint16_t>: SqlSimpleDataBinder<uint16_t, SQL_C_USHORT, SQL_SMALLINT, SqlColumnTypeDefinitions::Smallint {}> {};
222template <>
struct SqlDataBinder<int32_t>: SqlSimpleDataBinder<int32_t, SQL_C_SLONG, SQL_INTEGER, SqlColumnTypeDefinitions::Integer {}> {};
223template <>
struct SqlDataBinder<uint32_t>: SqlSimpleDataBinder<uint32_t, SQL_C_ULONG, SQL_INTEGER, SqlColumnTypeDefinitions::Integer {}> {};
224template <>
struct SqlDataBinder<int64_t>: Int64DataBinderHelper<int64_t, SQL_C_SBIGINT> {};
225template <>
struct SqlDataBinder<uint64_t>: Int64DataBinderHelper<uint64_t, SQL_C_UBIGINT> {};
227template <>
struct SqlDataBinder<float>: SqlSimpleDataBinder<float, SQL_C_FLOAT, SQL_REAL, SqlColumnTypeDefinitions::Real { .precision = 24 }> {};
228template <>
struct SqlDataBinder<double>: SqlSimpleDataBinder<double, SQL_C_DOUBLE, SQL_DOUBLE, SqlColumnTypeDefinitions::Real { .precision = 53 }> {};
229#if !defined(_WIN32) && !defined(__APPLE__)
230template <>
struct SqlDataBinder<long long>: Int64DataBinderHelper<long long, SQL_C_SBIGINT> {};
231template <>
struct SqlDataBinder<unsigned long long>: Int64DataBinderHelper<unsigned long long, SQL_C_UBIGINT> {};
233#if defined(__APPLE__)
236template <>
struct SqlDataBinder<std::size_t>: SqlSimpleDataBinder<std::size_t, SQL_C_UBIGINT, SQL_BIGINT, SqlColumnTypeDefinitions::Bigint {}> {};
247 requires detail::IsAnyOf<T, bool, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t,
249#if !defined(_WIN32) && !defined(__APPLE__)
250 ,
long long,
unsigned long long
252#if defined(__APPLE__)
256inline constexpr bool SqlIsNativeRowBindableValue<T> =
true;
virtual SQLLEN * ProvideInputIndicators(size_t rowCount)=0
static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(char value)
static SQLRETURN OutputColumn(SQLHSTMT stmt, SQLUSMALLINT column, char *result, SQLLEN *indicator, SqlDataBinderCallback &cb) noexcept
static SQLRETURN GetColumn(SQLHSTMT stmt, SQLUSMALLINT column, char *result, SQLLEN *indicator, SqlDataBinderCallback const &) noexcept
static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt, SQLUSMALLINT column, char const &value, SqlDataBinderCallback &cb) noexcept
static LIGHTWEIGHT_FORCE_INLINE SQLRETURN BatchInputParameter(SQLHSTMT stmt, SQLUSMALLINT column, char const *values, size_t rowCount, SqlDataBinderCallback &cb, SQLLEN *indicators=nullptr) noexcept