libsl3 1.2.41002
A C++ interface for SQLite
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sl3::Columns Class Reference

Class to access data of query results. More...

#include <sl3/columns.hpp>

Public Member Functions

 Columns (Columns &&)=default
 Move constructor A column is movable.
 
 ~Columns ()=default
 Destructor.
 
int count () const
 Number of columns in the statement.
 
std::string getName (int idx) const
 Column name of given index.
 
std::vector< std::string > getNames () const
 Get columns names.
 
DbValue getValue (int idx) const
 Get the value at a given index.
 
DbValue getValue (int idx, Type type) const
 Get the value at a given index.
 
DbValues getRow () const
 Get all columns at once.
 
DbValues getRow (const Types &types) const
 Get all columns at once using the given types.
 
Type getType (int idx) const
 Get the sqlite type for a column.
 
size_t getSize (int idx) const
 Get the size of a column.
 
std::string getText (int idx) const
 Get the value of a column.
 
int getInt (int idx) const
 Get the value of a column.
 
int64_t getInt64 (int idx) const
 Get the value of a column.
 
double getReal (int idx) const
 Get the value of a column.
 
Blob getBlob (int idx) const
 Get the value of a column.
 
sqlite3_stmt * get_stmt () const
 Get the underlying sqlite3_stmt.
 

Detailed Description

Class to access data of query results.

A Columns instance is constructed by a Command and passed to the callback which handles the results of a query.

See also
RowCallback
Command::Callback
Database::Callback

Constructor & Destructor Documentation

◆ Columns()

sl3::Columns::Columns ( Columns &&  )
default

Move constructor A column is movable.

◆ ~Columns()

sl3::Columns::~Columns ( )
default

Destructor.

Member Function Documentation

◆ count()

int sl3::Columns::count ( ) const

Number of columns in the statement.

Returns
number of columns

◆ get_stmt()

sqlite3_stmt * sl3::Columns::get_stmt ( ) const
inline

Get the underlying sqlite3_stmt.

User defined QueryCallbacks might have their own way to do things, so this getter provides access to the underlying sqlite3_stmt.

Returns
underlying sqlite3_stmt

◆ getBlob()

Blob sl3::Columns::getBlob ( int  idx) const

Get the value of a column.

If a column is Null of of a different type, the sqlite3 conversion rules are applied.

Parameters
idxcolumn index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
column value

◆ getInt()

int sl3::Columns::getInt ( int  idx) const

Get the value of a column.

If a column is Null of of a different type, the sqlite3 conversion rules are applied.

Parameters
idxcolumn index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
column value

◆ getInt64()

int64_t sl3::Columns::getInt64 ( int  idx) const

Get the value of a column.

If a column is Null of of a different type, the sqlite3 conversion rules are applied.

Parameters
idxcolumn index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
column value

◆ getName()

std::string sl3::Columns::getName ( int  idx) const

Column name of given index.

Exceptions
sl3::ErrOutOfRangeif idx is invalid,
Parameters
idxwanted column index
Returns
column name or an empty string if index is invalid

◆ getNames()

std::vector< std::string > sl3::Columns::getNames ( ) const

Get columns names.

Will return a list of size count() . Unnamed columns will be an ampty string

Returns
the names

◆ getReal()

double sl3::Columns::getReal ( int  idx) const

Get the value of a column.

If a column is Null of of a different type, the sqlite3 conversion rules are applied.

Parameters
idxcolumn index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
column value

◆ getRow() [1/2]

DbValues sl3::Columns::getRow ( ) const

Get all columns at once.

All DbValue object will be of Type::Variant

Returns
DbValues of the column values

◆ getRow() [2/2]

DbValues sl3::Columns::getRow ( const Types types) const

Get all columns at once using the given types.

If a value does not math the given types an exception will be thown

Parameters
typeswanted Types
Exceptions
sl3::ErrTypeMisMatchin case of an incorrect type
Returns
DbValues of the column values

◆ getSize()

size_t sl3::Columns::getSize ( int  idx) const

Get the size of a column.

The size sqlite3 uses to store the value of the given field.

Parameters
idxwanted index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
size sqlite uses for the column

◆ getText()

std::string sl3::Columns::getText ( int  idx) const

Get the value of a column.

If a column is Null of of a different type, the sqlite3 conversion rules are applied.

Parameters
idxcolumn index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
column value

◆ getType()

Type sl3::Columns::getType ( int  idx) const

Get the sqlite type for a column.

If used, should be called before accessing the value of the column at the given index, otherwise the typed access might set the type.

This method can be used to check if a column isNull.

Parameters
idxwanted index
Exceptions
sl3::ErrOutOfRangeif idx is invalid
Returns
Type sqlite interprets the value

◆ getValue() [1/2]

DbValue sl3::Columns::getValue ( int  idx) const

Get the value at a given index.

The returned DbValue::getType() will be a Type::Variant and DbValue::getStorageType() will be set to the sqlite3 storage type.

Parameters
idxwanted index
Exceptions
sl3::ErrOutOfRangeif idx is invalid,
Returns
DbValue of requested column

◆ getValue() [2/2]

DbValue sl3::Columns::getValue ( int  idx,
Type  type 
) const

Get the value at a given index.

The returned DbValue::getType() and DbValue::getStorageType() will be set to the given type.

Parameters
idxwanted index
typewanted type
Exceptions
sl3::ErrTypeMisMatchif type is not the sqlite type
sl3::ErrOutOfRangeif idx is invalid,
Returns
DbValue of requested column

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