5#include "../SqlColumnTypeDefinitions.hpp"
31 static std::optional<
SqlGuid> TryParse(std::string_view const& text) noexcept;
34 static
SqlGuid constexpr UnsafeParse(std::string_view const& text) noexcept;
37 constexpr std::weak_ordering operator<=>(
SqlGuid const& other) const noexcept = default;
40 constexpr
bool operator==(
SqlGuid const& other) const noexcept
42 return (*this <=> other) == std::weak_ordering::equivalent;
48 return !(*
this == other);
52 constexpr explicit operator bool() const noexcept
60 return !
static_cast<bool>(*this);
72 if (text.size() != 36)
76 if (text[8] !=
'-' || text[13] !=
'-' || text[18] !=
'-' || text[23] !=
'-')
80 auto const version = text[14];
81 if (!(
'1' <= version && version <=
'5'))
86 auto const variant = text[19];
87 auto const isHexDigit =
88 (variant >=
'0' && variant <=
'9') || (variant >=
'A' && variant <=
'F') || (variant >=
'a' && variant <=
'f');
94 for (
auto const index: { 0, 2, 4, 6,
98 24, 26, 28, 30, 32, 34 })
100 if (std::from_chars(text.data() + index, text.data() + index + 2, guid.data[i], 16).ec != std::errc())
112struct std::formatter<Lightweight::SqlGuid>: std::formatter<std::string>
114 LIGHTWEIGHT_FORCE_INLINE
auto format(
Lightweight::SqlGuid const& guid, format_context& ctx)
const
115 -> format_context::iterator
118 return formatter<std::string>::format(std::format(
119 "{:08X}-{:04X}-{:04X}-{:04X}-{:012X}",
120 (uint32_t) guid.data[3] | (uint32_t) guid.data[2] << 8 |
121 (uint32_t) guid.data[1] << 16 | (uint32_t) guid.data[0] << 24,
122 (uint16_t) guid.data[5] | (uint16_t) guid.data[4] << 8,
123 (uint16_t) guid.data[7] | (uint16_t) guid.data[6] << 8,
124 (uint16_t) guid.data[9] | (uint16_t) guid.data[8] << 8,
125 (uint64_t) guid.data[15] | (uint64_t) guid.data[14] << 8 |
126 (uint64_t) guid.data[13] << 16 | (uint64_t) guid.data[12] << 24 |
127 (uint64_t) guid.data[11] << 32 | (uint64_t) guid.data[10] << 40
138inline LIGHTWEIGHT_FORCE_INLINE std::string to_string(SqlGuid
const& guid)
140 return std::format(
"{}", guid);
157 inline void SwapGuidWireByteOrder(std::span<uint8_t, 16> data)
noexcept
163 static_assert(std::endian::native == std::endian::little);
167 std::ranges::reverse(data.first<4>());
168 std::ranges::reverse(data.subspan<4, 2>());
169 std::ranges::reverse(data.subspan<6, 2>());
174struct LIGHTWEIGHT_API SqlDataBinder<SqlGuid>
176 static constexpr auto ColumnType = SqlColumnTypeDefinitions::Guid {};
178 static SQLRETURN InputParameter(SQLHSTMT stmt,
180 SqlGuid
const& value,
181 SqlDataBinderCallback& cb)
noexcept;
183 static SQLRETURN OutputColumn(
184 SQLHSTMT stmt, SQLUSMALLINT column, SqlGuid* result, SQLLEN* indicator, SqlDataBinderCallback& cb)
noexcept;
186 static SQLRETURN GetColumn(
187 SQLHSTMT stmt, SQLUSMALLINT column, SqlGuid* result, SQLLEN* indicator, SqlDataBinderCallback
const& cb)
noexcept;
189 static LIGHTWEIGHT_FORCE_INLINE std::string Inspect(SqlGuid
const& value)
noexcept
191 return std::format(
"{}", value);
constexpr bool operator!=(SqlGuid const &other) const noexcept
Inequality comparison operator.
static SqlGuid constexpr UnsafeParse(std::string_view const &text) noexcept
Parses a GUID from a string. Use with caution and always prefer TryParse at all cost.
constexpr bool operator!() const noexcept
Tests if the GUID is empty.
static SqlGuid Create() noexcept
Creates a new non-empty GUID.