Lightweight 0.1.0
Loading...
Searching...
No Matches
StringLiteral.hpp
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "Core.hpp"
6#include "UnicodeConverter.hpp"
7
8#include <concepts>
9
10template <std::size_t N>
11struct SqlDataBinder<char[N]>
12{
13 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
14 SQLUSMALLINT column,
15 char const* value,
16 SqlDataBinderCallback& /*cb*/) noexcept
17 {
18 return SQLBindParameter(
19 stmt, column, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, N - 1, 0, (SQLPOINTER) value, 0, nullptr);
20 }
21
22 static LIGHTWEIGHT_FORCE_INLINE std::string_view Inspect(char const* value) noexcept
23 {
24 return { value, N * sizeof(char) };
25 }
26};
27
28template <typename T, std::size_t N>
29 requires(std::same_as<T, char16_t> || (std::same_as<T, wchar_t> && sizeof(wchar_t) == 2))
30struct SqlDataBinder<T[N]>
31{
32 static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter(SQLHSTMT stmt,
33 SQLUSMALLINT column,
34 T const* value,
35 SqlDataBinderCallback& /*cb*/) noexcept
36 {
37 return SQLBindParameter(stmt,
38 column,
39 SQL_PARAM_INPUT,
40 SQL_C_WCHAR,
41 SQL_WVARCHAR,
42 (N - 1) * sizeof(T),
43 0,
44 (SQLPOINTER) value,
45 0,
46 nullptr);
47 }
48
49 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(T const* value) noexcept
50 {
51 auto u8String = ToUtf8(std::basic_string_view<T> { value, N });
52 return std::string((char const*) u8String.data(), u8String.size());
53 }
54};
LIGHTWEIGHT_API std::u8string ToUtf8(std::u32string_view u32InputString)