5#include "../SqlColumnTypeDefinitions.hpp"
6#include "BasicStringBinder.hpp"
25 using std::vector<uint8_t>::vector;
31 return static_cast<std::vector<uint8_t> const&
>(*this) <=>
static_cast<std::vector<uint8_t> const&
>(other);
37 return static_cast<std::vector<uint8_t> const&
>(*this) ==
static_cast<std::vector<uint8_t> const&
>(other);
43 mutable SQLLEN _indicator = 0;
47struct SqlDataBinder<SqlBinary>
49 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Binary { 255 };
51 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
53 SqlBinary
const& value,
54 SqlDataBinderCallback& )
noexcept
56 value._indicator =
static_cast<SQLLEN
>(value.size());
61 static constexpr std::uint8_t emptySentinel = 0;
62 bool const isEmpty = value.empty();
63 auto const* dataPtr = isEmpty ? &emptySentinel : value.data();
64 SQLULEN
const columnSize = isEmpty ? SQLULEN { 1 } :
static_cast<SQLULEN
>(value.size());
65 return SQLBindParameter(stmt,
77 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN OutputColumn(
78 SQLHSTMT stmt, SQLUSMALLINT column, SqlBinary* result, SQLLEN* indicator, SqlDataBinderCallback& cb)
noexcept
83 cb.PlanPostProcessOutputColumn([stmt, column, result, indicator]() {
84 if (*indicator == SQL_NULL_DATA)
87 else if (*indicator == SQL_NO_TOTAL)
89 result->resize(result->size() - 1);
90 else if (std::cmp_less_equal(*indicator,
static_cast<SQLLEN
>(result->size())))
91 result->resize(
static_cast<size_t>(*indicator));
97 auto const totalCharsRequired = *indicator;
98 result->resize(
static_cast<size_t>(totalCharsRequired) + 1);
99 auto const sqlResult =
100 SQLGetData(stmt, column, SQL_C_BINARY, (SQLPOINTER) result->data(), totalCharsRequired + 1, indicator);
102 assert(SQL_SUCCEEDED(sqlResult));
103 assert(*indicator == totalCharsRequired);
104 result->resize(
static_cast<size_t>(totalCharsRequired));
108 return SQLBindCol(stmt, column, SQL_C_BINARY, (SQLPOINTER) result->data(), 255, indicator);
111 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN GetColumn(SQLHSTMT stmt,
115 SqlDataBinderCallback
const& )
noexcept
120 return detail::GetRawColumnArrayData<SQL_C_BINARY>(stmt, column, result, indicator);
123 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(SqlBinary
const& value)
125 return std::format(
"SqlBinary(size={})", value.size());
Represents a binary data type.
constexpr auto operator<=>(SqlBinary const &other) const noexcept
constexpr bool operator==(SqlBinary const &other) const noexcept
Equality operator derived from the spaceship comparison above.