|
Lightweight 0.20261105.1
|
Represents a value that can be any of the supported SQL data types. More...
#include <SqlVariant.hpp>
Public Types | |
| using | InnerType = std::variant< SqlNullType, SqlGuid, bool, int8_t, short, unsigned short, int, unsigned int, long long, unsigned long long, float, double, std::string, std::string_view, std::u16string, std::u16string_view, SqlText, SqlBinary, SqlDynamicNumeric, SqlDate, SqlTime, SqlDateTime > |
| The inner type of the variant. | |
Public Member Functions | |
| SqlVariant ()=default | |
| Default construct a new SqlVariant. | |
| SqlVariant (SqlVariant const &)=default | |
| Copy construct a new SqlVariant from another. | |
| SqlVariant (SqlVariant &&) noexcept=default | |
| Move construct a new SqlVariant from another. | |
| SqlVariant & | operator= (SqlVariant const &)=default |
| Copy assign a new SqlVariant from another. | |
| SqlVariant & | operator= (SqlVariant &&) noexcept=default |
| Move assign a new SqlVariant from another. | |
| ~SqlVariant ()=default | |
| Destructor for SqlVariant. | |
| LIGHTWEIGHT_FORCE_INLINE | SqlVariant (InnerType const &other) |
| Copy constructor of a SqlVariant from one of the supported types. | |
| LIGHTWEIGHT_FORCE_INLINE | SqlVariant (InnerType &&other) noexcept |
| Move constructor of a SqlVariant from one of the supported types. | |
| template<std::size_t N, typename T = char, SqlFixedStringMode Mode> | |
| constexpr LIGHTWEIGHT_FORCE_INLINE | SqlVariant (SqlFixedString< N, T, Mode > const &other) |
| Construct a new SqlVariant from a SqlFixedString. | |
| template<std::size_t N> | |
| LIGHTWEIGHT_FORCE_INLINE | SqlVariant (SqlDynamicBinary< N > const &other) |
| Construct a new SqlVariant from a SqlDynamicBinary, holding a copy of its bytes as SqlBinary. This is what lets a binary column be compared in a query builder's WHERE clause, which binds its values as SqlVariant. | |
| template<std::size_t TextSize> | |
| constexpr LIGHTWEIGHT_FORCE_INLINE | SqlVariant (char const (&text)[TextSize]) |
| Copy constructor of a SqlVariant from a char array. | |
| template<std::size_t TextSize> | |
| constexpr LIGHTWEIGHT_FORCE_INLINE | SqlVariant (char16_t const (&text)[TextSize]) |
| Copy constructor of a SqlVariant from a char16_t array. | |
| template<typename T > | |
| LIGHTWEIGHT_FORCE_INLINE | SqlVariant (std::optional< T > const &other) |
| Copy constructor of a SqlVariant from an optional of one of the supported types. | |
| LIGHTWEIGHT_FORCE_INLINE SqlVariant & | operator= (InnerType const &other) |
| Assignment operator of a SqlVariant from one of the supported types. | |
| LIGHTWEIGHT_FORCE_INLINE SqlVariant & | operator= (InnerType &&other) noexcept |
| Assignment operator of a SqlVariant from one of the supported types. | |
| template<detail::HasSqlViewHelper StringViewLike> | |
| LIGHTWEIGHT_FORCE_INLINE | SqlVariant (StringViewLike const *newValue) |
| Construct from an string-like object that implements an SqlViewHelper<>. | |
| template<detail::HasSqlViewHelper StringViewLike> | |
| LIGHTWEIGHT_FORCE_INLINE SqlVariant & | operator= (StringViewLike const *newValue) noexcept |
| Assign from an string-like object that implements an SqlViewHelper<>. | |
| LIGHTWEIGHT_FORCE_INLINE bool | IsNull () const noexcept |
| Check if the value is NULL. | |
| template<typename T > | |
| LIGHTWEIGHT_FORCE_INLINE bool | Is () const noexcept |
| Check if the value is of the specified type. | |
| template<typename T > | |
| LIGHTWEIGHT_FORCE_INLINE decltype(auto) | Get () |
| Retrieve the value as the specified type. | |
| template<typename T > | |
| LIGHTWEIGHT_FORCE_INLINE T | ValueOr (T &&defaultValue) const noexcept |
| Retrieve the value as the specified type, or return the default value if the value is NULL. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< bool > | TryGetBool () const noexcept |
| Retrieve the bool from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< int8_t > | TryGetInt8 () const noexcept |
| Retrieve the int8_t from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< short > | TryGetShort () const noexcept |
| Retrieve the unsigned short from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned short > | TryGetUShort () const noexcept |
| Retrieve the unsigned short from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< int > | TryGetInt () const noexcept |
| Retrieve the int from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned int > | TryGetUInt () const noexcept |
| Retrieve the unsigned int from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< long long > | TryGetLongLong () const noexcept |
| Retrieve the long long from the variant or std::nullopt. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned long long > | TryGetULongLong () const noexcept |
| Retrieve the unsigned long long from the variant or std::nullopt. | |
| std::optional< std::string_view > | TryGetStringView () const noexcept |
Retrieves a string view from the variant, or std::nullopt if the variant is NULL or holds a non-string alternative. The function is noexcept, so it must not propagate bad_variant_access. | |
| std::optional< std::u16string_view > | TryGetUtf16StringView () const noexcept |
Retrieves a UTF-16 string view from the variant, or std::nullopt if the variant is NULL or holds a non-string alternative. The function is noexcept, so it must not propagate bad_variant_access. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDate > | TryGetDate () const |
| function to get SqlDate from SqlVariant or std::nullopt | |
| bool | operator== (SqlVariant const &other) const noexcept |
| Equality comparison operator. | |
| bool | operator!= (SqlVariant const &other) const noexcept |
| Inequality comparison operator. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< SqlTime > | TryGetTime () const |
| function to get SqlTime from SqlVariant or std::nullopt | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDateTime > | TryGetDateTime () const |
| function to get SqlDateTime from SqlVariant or std::nullopt | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< SqlGuid > | TryGetGuid () const |
| Retrieve the GUID from the variant or std::nullopt if the value is NULL. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDynamicNumeric > | TryGetNumeric () const |
| Retrieve the exact fixed-point decimal from the variant, or std::nullopt if NULL. | |
| LIGHTWEIGHT_FORCE_INLINE std::optional< SqlBinary > | TryGetBinary () const |
| Retrieve the binary payload from the variant, or std::nullopt if the value is NULL. | |
| LIGHTWEIGHT_API std::string | ToString () const |
| Create string representation of the variant. Can be used for debug purposes. | |
Public Attributes | |
| InnerType | value |
| The variant value. | |
Represents a value that can be any of the supported SQL data types.
Use this class with care. Always prefer native types when possible, in order to avoid any unnecessary overhead.
Definition at line 47 of file SqlVariant.hpp.
| using Lightweight::SqlVariant::InnerType = std::variant<SqlNullType, SqlGuid, bool, int8_t, short, unsigned short, int, unsigned int, long long, unsigned long long, float, double, std::string, std::string_view, std::u16string, std::u16string_view, SqlText, SqlBinary, SqlDynamicNumeric, SqlDate, SqlTime, SqlDateTime> |
The inner type of the variant.
This type is a variant of all the supported SQL data types.
Definition at line 52 of file SqlVariant.hpp.
|
inline |
Copy constructor of a SqlVariant from one of the supported types.
Definition at line 92 of file SqlVariant.hpp.
|
inlinenoexcept |
Move constructor of a SqlVariant from one of the supported types.
Definition at line 98 of file SqlVariant.hpp.
|
inlineconstexpr |
Construct a new SqlVariant from a SqlFixedString.
Definition at line 105 of file SqlVariant.hpp.
|
inline |
Construct a new SqlVariant from a SqlDynamicBinary, holding a copy of its bytes as SqlBinary. This is what lets a binary column be compared in a query builder's WHERE clause, which binds its values as SqlVariant.
Definition at line 114 of file SqlVariant.hpp.
|
inlineconstexpr |
Copy constructor of a SqlVariant from a char array.
Definition at line 121 of file SqlVariant.hpp.
|
inlineconstexpr |
Copy constructor of a SqlVariant from a char16_t array.
Definition at line 128 of file SqlVariant.hpp.
|
inline |
Copy constructor of a SqlVariant from an optional of one of the supported types.
Definition at line 135 of file SqlVariant.hpp.
|
inlineexplicit |
Construct from an string-like object that implements an SqlViewHelper<>.
Definition at line 156 of file SqlVariant.hpp.
|
inline |
Assignment operator of a SqlVariant from one of the supported types.
Definition at line 141 of file SqlVariant.hpp.
References value.
|
inlinenoexcept |
Assignment operator of a SqlVariant from one of the supported types.
Definition at line 148 of file SqlVariant.hpp.
References value.
|
inlinenoexcept |
Assign from an string-like object that implements an SqlViewHelper<>.
Definition at line 163 of file SqlVariant.hpp.
References value.
|
inlinenoexcept |
Check if the value is NULL.
Definition at line 170 of file SqlVariant.hpp.
References value.
Referenced by Get(), TryGetBinary(), TryGetDate(), TryGetDateTime(), TryGetGuid(), TryGetNumeric(), TryGetStringView(), TryGetTime(), TryGetUtf16StringView(), and ValueOr().
|
inlinenoexcept |
Check if the value is of the specified type.
Definition at line 177 of file SqlVariant.hpp.
References value.
|
inline |
Retrieve the value as the specified type.
std::string T converts from those and therefore yields a value rather than a reference. Use TryGetNumeric when the exact decimal matters. | std::bad_variant_access | The variant holds neither T nor one of the alternatives converted above. Use the TryGet* accessors to probe instead. |
Definition at line 191 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the value as the specified type, or return the default value if the value is NULL.
T is asked for, so callers written against the arithmetic/string alternatives keep working. Reach for TryGetNumeric when the exact decimal matters. Definition at line 225 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the bool from the variant or std::nullopt.
Definition at line 257 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the int8_t from the variant or std::nullopt.
Definition at line 259 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the unsigned short from the variant or std::nullopt.
Definition at line 261 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the unsigned short from the variant or std::nullopt.
Definition at line 263 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the int from the variant or std::nullopt.
Definition at line 265 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the unsigned int from the variant or std::nullopt.
Definition at line 267 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the long long from the variant or std::nullopt.
Definition at line 269 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieve the unsigned long long from the variant or std::nullopt.
Definition at line 271 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieves a string view from the variant, or std::nullopt if the variant is NULL or holds a non-string alternative. The function is noexcept, so it must not propagate bad_variant_access.
Definition at line 304 of file SqlVariant.hpp.
|
inlinenoexcept |
Retrieves a UTF-16 string view from the variant, or std::nullopt if the variant is NULL or holds a non-string alternative. The function is noexcept, so it must not propagate bad_variant_access.
Definition at line 326 of file SqlVariant.hpp.
|
inline |
function to get SqlDate from SqlVariant or std::nullopt
Definition at line 342 of file SqlVariant.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Inequality comparison operator.
Definition at line 367 of file SqlVariant.hpp.
|
inline |
function to get SqlTime from SqlVariant or std::nullopt
Definition at line 373 of file SqlVariant.hpp.
|
inline |
function to get SqlDateTime from SqlVariant or std::nullopt
Definition at line 393 of file SqlVariant.hpp.
|
inline |
Retrieve the GUID from the variant or std::nullopt if the value is NULL.
Definition at line 405 of file SqlVariant.hpp.
|
inline |
Retrieve the exact fixed-point decimal from the variant, or std::nullopt if NULL.
DECIMAL and NUMERIC columns land on this alternative, keeping every digit the column declares. Use SqlDynamicNumeric::ToDouble only where an approximation is acceptable.
| std::bad_variant_access | The value is neither NULL nor a fixed-point decimal. |
Definition at line 422 of file SqlVariant.hpp.
|
inline |
Retrieve the binary payload from the variant, or std::nullopt if the value is NULL.
BINARY, VARBINARY and LONGVARBINARY columns land on this alternative, which keeps the bytes distinguishable from text so they bind back as SQL_C_BINARY.
| std::bad_variant_access | The value is neither NULL nor binary. |
Definition at line 439 of file SqlVariant.hpp.
| InnerType Lightweight::SqlVariant::value |
The variant value.
Definition at line 76 of file SqlVariant.hpp.
Referenced by Get(), Is(), IsNull(), operator=(), operator=(), operator=(), TryGetBinary(), TryGetDate(), TryGetDateTime(), TryGetGuid(), TryGetNumeric(), TryGetStringView(), TryGetTime(), TryGetUtf16StringView(), and ValueOr().