libsl3  1.12.2
C++ interface for sqlite3
Public Member Functions | Friends | List of all members
sl3::DbValue Class Reference

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. More...
 
 DbValue (int val, Type type=Type::Int)
 Constructor. More...
 
 DbValue (int64_t val, Type type=Type::Int)
 Constructor. More...
 
 DbValue (std::string val, Type type=Type::Text)
 Constructor. More...
 
 DbValue (double val, Type type=Type::Real)
 Constructor. More...
 
 DbValue (Blob val, Type type=Type::Blob)
 Constructor. More...
 
 ~DbValue () noexcept=default
 Destructor. More...
 
 DbValue (const DbValue &) noexcept=default
 Copy constructor. More...
 
 DbValue (DbValue &&) noexcept=default
 Move constructor. More...
 
DbValueoperator= (const DbValue &val)
 Assignment. More...
 
DbValueoperator= (DbValue &&val)
 Assignment. More...
 
DbValueoperator= (int val)
 Assignment. More...
 
DbValueoperator= (const int64_t &val)
 Assignment. More...
 
DbValueoperator= (const double &val)
 Assignment. More...
 
DbValueoperator= (const std::string &val)
 Assignment. More...
 
DbValueoperator= (const char *val)
 Assignment. More...
 
DbValueoperator= (const Blob &val)
 Assignment. More...
 
DbValueoperator= (const Value &val)
 Assignment. More...
 
void set (int val)
 Assignment. More...
 
void set (int64_t val)
 Assignment. More...
 
void set (const std::string &val)
 Assignment. More...
 
void set (double val)
 Assignment. More...
 
void set (const Blob &val)
 Assignment. More...
 
const ValuegetValue () const noexcept
 Value access. More...
 
const Valuevalue () const noexcept
 Value access Just s shorter way tan getValue. More...
 
const int64_t & getInt () const
 Value access. More...
 
const double & getReal () const
 Value access. More...
 
const std::string & getText () const
 Value access. More...
 
const BlobgetBlob () const
 Value access. More...
 
int64_t getInt (int64_t defval) const
 Value access with default for a NULL value. More...
 
double getReal (double defval) const
 Value access with default for a NULL value.; More...
 
std::string getText (const std::string &defval) const
 Value access with default for a NULL value.; More...
 
Blob getBlob (const Blob &defval) const
 Value access with default for a NULL value.; More...
 
int64_t get (int64_t defval) const
 Value access with default for a NULL and different type value. More...
 
int64_t get (int defval) const
 Value access with default for a NULL and different type value.; More...
 
double get (double defval) const
 Value access with default for a NULL and different type value.; More...
 
std::string get (const std::string &defval) const
 Value access with default for a NULL and different type value.; More...
 
Blob get (const Blob &defval) const
 Value access with default for a NULL and different type value.; More...
 
std::string ejectText ()
 Moves the current value into the return value. More...
 
Blob ejectBlob ()
 Moves the current value into the return value. More...
 
void setNull ()
 Set to NULL. More...
 
bool isNull () const
 Check Null. More...
 
Type dbtype () const
 The Type of the value. More...
 
Type type () const
 Returns the type of the underlying Value. More...
 
bool canAssign (const DbValue &other) const
 Check if assignment would be OK. More...
 

Friends

void swap (DbValue &a, DbValue &b) noexcept
 Swap 2 DbValues. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DbValue() [1/8]

sl3::DbValue::DbValue ( Type  type)
noexcept

Constructor.

Constructs a type and the value is null.

Parameters
typewanted storage type If Type::Null is given, the type will be a variant.

◆ DbValue() [2/8]

sl3::DbValue::DbValue ( int  val,
Type  type = Type::Int 
)
explicit

Constructor.

This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.

Exceptions
sl3::ErrTypeMisMatchif given type is incompatible
Parameters
valinitial value
typewanted type, default set to type but can be set to DbValue::Variant if waned

◆ DbValue() [3/8]

sl3::DbValue::DbValue ( int64_t  val,
Type  type = Type::Int 
)
explicit

Constructor.

This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.

Exceptions
sl3::ErrTypeMisMatchif given type is incompatible
Parameters
valinitial value
typewanted type, default set to type but can be set to DbValue::Variant if waned

◆ DbValue() [4/8]

sl3::DbValue::DbValue ( std::string  val,
Type  type = Type::Text 
)
explicit

Constructor.

This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.

Exceptions
sl3::ErrTypeMisMatchif given type is incompatible
Parameters
valinitial value
typewanted type, default set to type but can be set to DbValue::Variant if waned

◆ DbValue() [5/8]

sl3::DbValue::DbValue ( double  val,
Type  type = Type::Real 
)
explicit

Constructor.

This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.

Exceptions
sl3::ErrTypeMisMatchif given type is incompatible
Parameters
valinitial value
typewanted type, default set to type but can be set to DbValue::Variant if waned

◆ DbValue() [6/8]

sl3::DbValue::DbValue ( Blob  val,
Type  type = Type::Blob 
)
explicit

Constructor.

This constructor takes a initialization value, and optionally a type which can only be Type::Variant or the default one.

Exceptions
sl3::ErrTypeMisMatchif given type is incompatible
Parameters
valinitial value
typewanted type, default set to type but can be set to DbValue::Variant if waned

◆ ~DbValue()

sl3::DbValue::~DbValue ( )
defaultnoexcept

Destructor.

◆ DbValue() [7/8]

sl3::DbValue::DbValue ( const DbValue )
defaultnoexcept

Copy constructor.

◆ DbValue() [8/8]

sl3::DbValue::DbValue ( DbValue &&  )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ canAssign()

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.

Parameters
othervalue to check
Returns
true if the other value can be assigned

◆ dbtype()

Type sl3::DbValue::dbtype ( ) const

The Type of the value.

This is the type with which the Value has been created and will not change.

The type might be Type::Varian, so that a DbValue can hold any value, or a specific Type to guarantee the only the allow type is used.

Returns
the type

◆ ejectBlob()

Blob sl3::DbValue::ejectBlob ( )

Moves the current value into the return value.

After calling this function the value will be Null.

Exceptions
sl3::ErrTypeMisMatchin case of wrong type.
Returns
The value

◆ ejectText()

std::string sl3::DbValue::ejectText ( )

Moves the current value into the return value.

After calling this function the value will be Null.

Exceptions
sl3::ErrTypeMisMatchin case of wrong type.
Returns
The value

◆ get() [1/5]

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.

Parameters
defvaldefault value to return
Returns
the value or the give default value if the value needs to be replaced

◆ get() [2/5]

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.

Parameters
defvaldefault value to return
Returns
the value or the give default value if the value needs to be replaced;

◆ get() [3/5]

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.

Parameters
defvaldefault value to return
Returns
the value or the give default value if the value needs to be replaced;

◆ get() [4/5]

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.

Parameters
defvaldefault value to return
Returns
the value or the give default value if the value needs to be replaced;

◆ get() [5/5]

Blob sl3::DbValue::get ( const Blob 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.

Parameters
defvaldefault value to return
Returns
the value or the give default value if the value needs to be replaced;

◆ getBlob() [1/2]

const Blob& sl3::DbValue::getBlob ( ) const

Value access.

Exceptions
sl3::ErrNullValueAccessif value is null.
sl3::ErrTypeMisMatchif getType is incorrect
Returns
reference to the value

◆ getBlob() [2/2]

Blob sl3::DbValue::getBlob ( const Blob defval) const

Value access with default for a NULL value.;

Exceptions
sl3::ErrTypeMisMatchif getType is incorrect
Parameters
defvaldefault value to return if value is NULL
Returns
the value or the give defval in case value is NULL;

◆ getInt() [1/2]

const int64_t& sl3::DbValue::getInt ( ) const

Value access.

Exceptions
sl3::ErrNullValueAccessif value is null.
sl3::ErrTypeMisMatchif getType is incorrect
Returns
reference to the value

◆ getInt() [2/2]

int64_t sl3::DbValue::getInt ( int64_t  defval) const

Value access with default for a NULL value.

Exceptions
sl3::ErrTypeMisMatchif getType is incorrect
Parameters
defvaldefault value to return if value is NULL
Returns
the value or the give defval in case value is NULL

◆ getReal() [1/2]

const double& sl3::DbValue::getReal ( ) const

Value access.

Exceptions
sl3::ErrNullValueAccessif value is null.
sl3::ErrTypeMisMatchif getType is incorrect
Returns
reference to the value

◆ getReal() [2/2]

double sl3::DbValue::getReal ( double  defval) const

Value access with default for a NULL value.;

Exceptions
sl3::ErrTypeMisMatchif getType is incorrect
Parameters
defvaldefault value to return if value is NULL
Returns
the value or the give defval in case value is NULL;

◆ getText() [1/2]

const std::string& sl3::DbValue::getText ( ) const

Value access.

Exceptions
sl3::ErrNullValueAccessif value is null.
sl3::ErrTypeMisMatchif getType is incorrect
Returns
reference to the value

◆ getText() [2/2]

std::string sl3::DbValue::getText ( const std::string &  defval) const

Value access with default for a NULL value.;

Exceptions
sl3::ErrTypeMisMatchif getType is incorrect
Parameters
defvaldefault value to return if value is NULL
Returns
the value or the give defval in case value is NULL;

◆ getValue()

const Value& sl3::DbValue::getValue ( ) const
noexcept

Value access.

Returns
reference to the underlying Value

◆ isNull()

bool sl3::DbValue::isNull ( ) const

Check Null.

Returns
if the value is null

◆ operator=() [1/9]

DbValue& sl3::DbValue::operator= ( const DbValue val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [2/9]

DbValue& sl3::DbValue::operator= ( DbValue &&  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [3/9]

DbValue& sl3::DbValue::operator= ( int  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [4/9]

DbValue& sl3::DbValue::operator= ( const int64_t &  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [5/9]

DbValue& sl3::DbValue::operator= ( const double &  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [6/9]

DbValue& sl3::DbValue::operator= ( const std::string &  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [7/9]

DbValue& sl3::DbValue::operator= ( const char *  val)
inline

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [8/9]

DbValue& sl3::DbValue::operator= ( const Blob val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ operator=() [9/9]

DbValue& sl3::DbValue::operator= ( const Value val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value
Returns
reference to this

◆ set() [1/5]

void sl3::DbValue::set ( int  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value

◆ set() [2/5]

void sl3::DbValue::set ( int64_t  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value

◆ set() [3/5]

void sl3::DbValue::set ( const std::string &  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value

◆ set() [4/5]

void sl3::DbValue::set ( double  val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value

◆ set() [5/5]

void sl3::DbValue::set ( const Blob val)

Assignment.

Exceptions
sl3::ErrTypeMisMatchif getType is incompatible
Note
, only value assignment happens here, the type does not change, the storage type might change in case of type is a variant.
Parameters
valnew value

◆ setNull()

void sl3::DbValue::setNull ( )

Set to NULL.

◆ type()

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.

Returns
the type the value actual holds

◆ value()

const Value& sl3::DbValue::value ( ) const
inlinenoexcept

Value access Just s shorter way tan getValue.

Returns
reference to the underlying Value

Friends And Related Function Documentation

◆ swap

void swap ( DbValue a,
DbValue b 
)
friend

Swap 2 DbValues.

Parameters
afirst value to swap second value
bsecond value to swap with first

The documentation for this class was generated from the following file: