libsl3 1.2.41002
A C++ interface for SQLite
|
This class models the duck typing sqlite uses. It supports int, real, text, blob and null values. More...
#include <sl3/dbvalue.hpp>
Public Member Functions | |
DbValue (Type type) noexcept | |
Constructor. | |
DbValue (int val, Type type=Type::Int) | |
Constructor. | |
DbValue (int64_t val, Type type=Type::Int) | |
Constructor. | |
DbValue (std::string val, Type type=Type::Text) | |
Constructor. | |
DbValue (double val, Type type=Type::Real) | |
Constructor. | |
DbValue (Blob val, Type type=Type::Blob) | |
Constructor. | |
~DbValue () noexcept=default | |
Destructor. | |
DbValue (const DbValue &) noexcept=default | |
Copy constructor. | |
DbValue (DbValue &&) noexcept=default | |
Move constructor. | |
DbValue & | operator= (const DbValue &val) |
Assignment. | |
DbValue & | operator= (DbValue &&val) |
Assignment. | |
DbValue & | operator= (int val) |
Assignment. | |
DbValue & | operator= (const int64_t &val) |
Assignment. | |
DbValue & | operator= (const double &val) |
Assignment. | |
DbValue & | operator= (const std::string &val) |
Assignment. | |
DbValue & | operator= (const char *val) |
Assignment. | |
DbValue & | operator= (const Blob &val) |
Assignment. | |
DbValue & | operator= (const Value &val) |
Assignment. | |
void | set (int val) |
Assignment. | |
void | set (int64_t val) |
Assignment. | |
void | set (const std::string &val) |
Assignment. | |
void | set (double val) |
Assignment. | |
void | set (const Blob &val) |
Assignment. | |
const Value & | getValue () const noexcept |
Value access. | |
const Value & | value () const noexcept |
Value access Just s shorter way tan getValue. | |
const int64_t & | getInt () const |
Value access. | |
const double & | getReal () const |
Value access. | |
const std::string & | getText () const |
Value access. | |
const Blob & | getBlob () const |
Value access. | |
int64_t | getInt (int64_t defval) const |
Value access with default for a NULL value. | |
double | getReal (double defval) const |
Value access with default for a NULL value. ; | |
std::string | getText (const std::string &defval) const |
Value access with default for a NULL value. ; | |
Blob | getBlob (const Blob &defval) const |
Value access with default for a NULL value. ; | |
int64_t | get (int64_t defval) const |
Value access with default for a NULL and different type value. | |
int64_t | get (int defval) const |
Value access with default for a NULL and different type value. ; | |
double | get (double defval) const |
Value access with default for a NULL and different type value. ; | |
std::string | get (const std::string &defval) const |
Value access with default for a NULL and different type value. ; | |
Blob | get (const Blob &defval) const |
Value access with default for a NULL and different type value. ; | |
std::string | ejectText () |
Moves the current value into the return value. | |
Blob | ejectBlob () |
Moves the current value into the return value. | |
void | setNull () |
Set to NULL. | |
bool | isNull () const |
Check Null. | |
Type | dbtype () const |
The Type of the value. | |
Type | type () const |
Returns the type of the underlying Value. | |
bool | canAssign (const DbValue &other) const |
Check if assignment would be OK. | |
This class models the duck typing sqlite uses. It supports int, real, text, blob and null values.
The type can be a variant, to support all of the possible types, or it can be set explicit to a wanted type.
Using this type for communication with the database can ensure either type guarantee or give the flexibility of variant types.
If a type is of type variant, the storage type can be any of the supported types, otherwise, if the type is set to a specific type, it is guaranteed that the type will match, or an exception occurs.
|
noexcept |
Constructor.
Constructs a type and the value is null.
type | wanted storage type If Type::Null is given, the type will be a variant. |
Constructor.
This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.
sl3::ErrTypeMisMatch | if given type is incompatible |
val | initial value |
type | wanted type, default set to type but can be set to DbValue::Variant if waned |
Constructor.
This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.
sl3::ErrTypeMisMatch | if given type is incompatible |
val | initial value |
type | wanted type, default set to type but can be set to DbValue::Variant if waned |
|
explicit |
Constructor.
This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.
sl3::ErrTypeMisMatch | if given type is incompatible |
val | initial value |
type | wanted type, default set to type but can be set to DbValue::Variant if waned |
|
explicit |
Constructor.
This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.
sl3::ErrTypeMisMatch | if given type is incompatible |
val | initial value |
type | wanted type, default set to type but can be set to DbValue::Variant if waned |
|
explicit |
Constructor.
This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.
sl3::ErrTypeMisMatch | if given type is incompatible |
val | initial value |
type | wanted type, default set to type but can be set to DbValue::Variant if waned |
|
defaultnoexcept |
Destructor.
|
defaultnoexcept |
Copy constructor.
|
defaultnoexcept |
Move constructor.
bool sl3::DbValue::canAssign | ( | const DbValue & | other | ) | const |
Check if assignment would be OK.
If this function return true, the other value can be assign because it is type compatible.
other | value to check |
Type sl3::DbValue::dbtype | ( | ) | const |
Blob sl3::DbValue::ejectBlob | ( | ) |
Moves the current value into the return value.
After calling this function the value will be Null.
sl3::ErrTypeMisMatch | in case of wrong type. |
std::string sl3::DbValue::ejectText | ( | ) |
Moves the current value into the return value.
After calling this function the value will be Null.
sl3::ErrTypeMisMatch | in case of wrong type. |
Value access with default for a NULL and different type value. ;
This method will not throw. If the actual value is null or of a different type, the fiven default value will be returned.
defval | default value to return |
std::string sl3::DbValue::get | ( | const std::string & | defval | ) | const |
Value access with default for a NULL and different type value. ;
This method will not throw. If the actual value is null or of a different type, the fiven default value will be returned.
defval | default value to return |
double sl3::DbValue::get | ( | double | defval | ) | const |
Value access with default for a NULL and different type value. ;
This method will not throw. If the actual value is null or of a different type, the fiven default value will be returned.
defval | default value to return |
int64_t sl3::DbValue::get | ( | int | defval | ) | const |
Value access with default for a NULL and different type value. ;
This method will not throw. If the actual value is null or of a different type, the fiven default value will be returned.
defval | default value to return |
int64_t sl3::DbValue::get | ( | int64_t | defval | ) | const |
Value access with default for a NULL and different type value.
This method will not throw. If the actual value is null or of a different type, the fiven default value will be returned.
defval | default value to return |
const Blob & sl3::DbValue::getBlob | ( | ) | const |
Value access.
sl3::ErrNullValueAccess | if value is null. |
sl3::ErrTypeMisMatch | if getType is incorrect |
Value access with default for a NULL value. ;
sl3::ErrTypeMisMatch | if getType is incorrect |
defval | default value to return if value is NULL |
const int64_t & sl3::DbValue::getInt | ( | ) | const |
Value access.
sl3::ErrNullValueAccess | if value is null. |
sl3::ErrTypeMisMatch | if getType is incorrect |
int64_t sl3::DbValue::getInt | ( | int64_t | defval | ) | const |
Value access with default for a NULL value.
sl3::ErrTypeMisMatch | if getType is incorrect |
defval | default value to return if value is NULL |
const double & sl3::DbValue::getReal | ( | ) | const |
Value access.
sl3::ErrNullValueAccess | if value is null. |
sl3::ErrTypeMisMatch | if getType is incorrect |
double sl3::DbValue::getReal | ( | double | defval | ) | const |
Value access with default for a NULL value. ;
sl3::ErrTypeMisMatch | if getType is incorrect |
defval | default value to return if value is NULL |
const std::string & sl3::DbValue::getText | ( | ) | const |
Value access.
sl3::ErrNullValueAccess | if value is null. |
sl3::ErrTypeMisMatch | if getType is incorrect |
std::string sl3::DbValue::getText | ( | const std::string & | defval | ) | const |
Value access with default for a NULL value. ;
sl3::ErrTypeMisMatch | if getType is incorrect |
defval | default value to return if value is NULL |
|
noexcept |
bool sl3::DbValue::isNull | ( | ) | const |
Check Null.
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
|
inline |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
DbValue & sl3::DbValue::operator= | ( | const double & | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
DbValue & sl3::DbValue::operator= | ( | const int64_t & | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
DbValue & sl3::DbValue::operator= | ( | const std::string & | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
DbValue & sl3::DbValue::operator= | ( | int | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
void sl3::DbValue::set | ( | const Blob & | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
void sl3::DbValue::set | ( | const std::string & | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
void sl3::DbValue::set | ( | double | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
void sl3::DbValue::set | ( | int | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
void sl3::DbValue::set | ( | int64_t | val | ) |
Assignment.
sl3::ErrTypeMisMatch | if getType is incompatible |
val | new value |
void sl3::DbValue::setNull | ( | ) |
Set to NULL.
Type sl3::DbValue::type | ( | ) | const |
Returns the type of the underlying Value.
If getType() is a Variant this property returns the actual type information, otherwise it will be the same as type or null.
|
inlinenoexcept |