5#include "../SqlColumnTypeDefinitions.hpp"
8template <
typename T, SQLSMALLINT TheCType, SQLINTEGER TheSqlType, auto TheColumnType>
9struct SqlSimpleDataBinder
11 static constexpr SqlColumnTypeDefinition ColumnType = TheColumnType;
13 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
18 return SQLBindParameter(stmt, column, SQL_PARAM_INPUT, TheCType, TheSqlType, 0, 0, (SQLPOINTER) &value, 0,
nullptr);
21 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN OutputColumn(
24 return SQLBindCol(stmt, column, TheCType, result, 0, indicator);
27 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN
28 GetColumn(SQLHSTMT stmt, SQLUSMALLINT column, T* result, SQLLEN* indicator,
SqlDataBinderCallback const& )
noexcept
30 return SQLGetData(stmt, column, TheCType, result, 0, indicator);
33 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(T value)
35 return std::to_string(value);
39template <
typename Int64Type, SQLSMALLINT TheCType>
40struct Int64DataBinderHelper
42 static constexpr SqlColumnTypeDefinition ColumnType = SqlColumnTypeDefinitions::Bigint {};
44 static LIGHTWEIGHT_API SQLRETURN InputParameter(SQLHSTMT stmt,
46 Int64Type
const& value,
49 static LIGHTWEIGHT_API SQLRETURN OutputColumn(
50 SQLHSTMT stmt, SQLUSMALLINT column, Int64Type* result, SQLLEN* indicator,
SqlDataBinderCallback& cb)
noexcept;
52 static LIGHTWEIGHT_API SQLRETURN GetColumn(
53 SQLHSTMT stmt, SQLUSMALLINT column, Int64Type* result, SQLLEN* indicator,
SqlDataBinderCallback const& cb)
noexcept;
55 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(Int64Type value)
57 return std::to_string(value);
62template <>
struct SqlDataBinder<bool>: SqlSimpleDataBinder<bool, SQL_BIT, SQL_BIT, SqlColumnTypeDefinitions::Bool {}> {};
63template <>
struct SqlDataBinder<char>: SqlSimpleDataBinder<char, SQL_C_CHAR, SQL_CHAR, SqlColumnTypeDefinitions::Char {}> {};
64template <>
struct SqlDataBinder<int8_t>: SqlSimpleDataBinder<int8_t, SQL_C_STINYINT, SQL_TINYINT, SqlColumnTypeDefinitions::Tinyint {}> {};
65template <>
struct SqlDataBinder<uint8_t>: SqlSimpleDataBinder<uint8_t, SQL_C_UTINYINT, SQL_TINYINT, SqlColumnTypeDefinitions::Tinyint {}> {};
66template <>
struct SqlDataBinder<int16_t>: SqlSimpleDataBinder<int16_t, SQL_C_SSHORT, SQL_SMALLINT, SqlColumnTypeDefinitions::Smallint {}> {};
67template <>
struct SqlDataBinder<uint16_t>: SqlSimpleDataBinder<uint16_t, SQL_C_USHORT, SQL_SMALLINT, SqlColumnTypeDefinitions::Smallint {}> {};
68template <>
struct SqlDataBinder<int32_t>: SqlSimpleDataBinder<int32_t, SQL_C_SLONG, SQL_INTEGER, SqlColumnTypeDefinitions::Integer {}> {};
69template <>
struct SqlDataBinder<uint32_t>: SqlSimpleDataBinder<uint32_t, SQL_C_ULONG, SQL_INTEGER, SqlColumnTypeDefinitions::Integer {}> {};
70template <>
struct SqlDataBinder<int64_t>: Int64DataBinderHelper<int64_t, SQL_C_SBIGINT> {};
71template <>
struct SqlDataBinder<uint64_t>: Int64DataBinderHelper<uint64_t, SQL_C_UBIGINT> {};
73template <>
struct SqlDataBinder<float>: SqlSimpleDataBinder<float, SQL_C_FLOAT, SQL_REAL, SqlColumnTypeDefinitions::Real {}> {};
74template <>
struct SqlDataBinder<double>: SqlSimpleDataBinder<double, SQL_C_DOUBLE, SQL_DOUBLE, SqlColumnTypeDefinitions::Real {}> {};
75#if !defined(_WIN32) && !defined(__APPLE__)
76template <>
struct SqlDataBinder<long long>: Int64DataBinderHelper<long long, SQL_C_SBIGINT> {};
77template <>
struct SqlDataBinder<unsigned long long>: Int64DataBinderHelper<unsigned long long, SQL_C_UBIGINT> {};
80template <>
struct SqlDataBinder<std::size_t>: SqlSimpleDataBinder<std::size_t, SQL_C_SBIGINT, SqlColumnTypeDefinitions::Bigint {}> {};