6#include "UnicodeConverter.hpp"
13struct SqlDataBinder<std::basic_string_view<char>>
15 static constexpr SQLSMALLINT CType = SQL_C_CHAR;
16 static constexpr SQLSMALLINT SqlType = SQL_VARCHAR;
18 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
20 std::basic_string_view<char> value,
23 return SQLBindParameter(
24 stmt, column, SQL_PARAM_INPUT, CType, SqlType, value.size(), 0, (SQLPOINTER) value.data(), 0,
nullptr);
27 static LIGHTWEIGHT_FORCE_INLINE std::string_view Inspect(std::basic_string_view<char> value)
noexcept
29 return { value.data(), value.size() };
33template <
typename Char16Type>
34 requires std::same_as<Char16Type, char16_t> || (std::same_as<Char16Type, wchar_t> &&
sizeof(wchar_t) == 2)
35struct SqlDataBinder<std::basic_string_view<Char16Type>>
37 static constexpr SQLSMALLINT CType = SQL_C_WCHAR;
38 static constexpr SQLSMALLINT SqlType = SQL_WVARCHAR;
40 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
42 std::basic_string_view<Char16Type> value,
45 return SQLBindParameter(
46 stmt, column, SQL_PARAM_INPUT, CType, SqlType, value.size(), 0, (SQLPOINTER) value.data(), 0,
nullptr);
49 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(std::basic_string_view<Char16Type> value)
noexcept
51 auto u8String =
ToUtf8(value);
52 return std::string((
char const*) u8String.data(), u8String.size());
56template <
typename Char32Type>
57 requires std::same_as<Char32Type, char32_t> || (std::same_as<Char32Type, wchar_t> &&
sizeof(wchar_t) == 4)
58struct SqlDataBinder<std::basic_string_view<Char32Type>>
60 static constexpr SQLSMALLINT CType = SQL_C_WCHAR;
61 static constexpr SQLSMALLINT SqlType = SQL_WVARCHAR;
63 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
65 std::basic_string_view<Char32Type> value,
68 auto u16String = std::make_shared<std::u16string>(
ToUtf16(value));
69 cb.PlanPostExecuteCallback([u16String = u16String]() {});
70 auto const* data = u16String->data();
71 auto const sizeInBytes = u16String->size() *
sizeof(Char32Type);
72 return SQLBindParameter(
73 stmt, column, SQL_PARAM_INPUT, CType, SqlType, sizeInBytes, 0, (SQLPOINTER) data, 0,
nullptr);
76 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(std::basic_string_view<Char32Type> value)
noexcept
78 auto u8String =
ToUtf8(value);
79 return std::string((
char const*) u8String.data(), u8String.size());
84struct SqlDataBinder<std::u8string_view>
86 static constexpr SQLSMALLINT CType = SQL_C_WCHAR;
87 static constexpr SQLSMALLINT SqlType = SQL_WVARCHAR;
89 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
91 std::u8string_view value,
94 auto u16String = std::make_shared<std::u16string>(
ToUtf16(value));
95 cb.PlanPostExecuteCallback([u16String = u16String]() {});
96 auto const* data = u16String->data();
97 auto const sizeInBytes = u16String->size() *
sizeof(char8_t);
98 return SQLBindParameter(
99 stmt, column, SQL_PARAM_INPUT, CType, SqlType, sizeInBytes, 0, (SQLPOINTER) data, 0,
nullptr);
102 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(std::basic_string_view<char8_t> value)
noexcept
104 return std::string { (
char const*) value.data(), value.size() };
std::u16string ToUtf16(const std::basic_string_view< T > u32InputString)
LIGHTWEIGHT_API std::u8string ToUtf8(std::u32string_view u32InputString)