libsl3 1.3.51003
A C++ interface for SQLite
Loading...
Searching...
No Matches
sl3::Dataset Class Referencefinal

A utility for processing query results. More...

#include <sl3/dataset.hpp>

Inheritance diagram for sl3::Dataset:
sl3::Container< std::vector< DbValues > >

Public Types

typedef bool(* DbValueSort) (const DbValue &, const DbValue &)
 Typedef for a relation function signature.
Public Types inherited from sl3::Container< std::vector< DbValues > >
using container_type
using iterator
using const_iterator
using value_type
using reference
using const_reference
using size_type

Public Member Functions

 Dataset () noexcept
 Constructor.
 Dataset (Types types)
 Constructor with DbValuesTypeList as description.
 Dataset (const Dataset &)=default
 Copy Constructor.
 Dataset (Dataset &&) noexcept(std::is_nothrow_move_constructible< Container< DbValues > >::value &&std::is_nothrow_move_constructible< Types >::value &&std::is_nothrow_move_constructible< std::vector< std::string > >::value)
 Move Constructor.
Datasetoperator= (const Dataset &)=default
 Value assignment.
Datasetoperator= (Dataset &&)=default
 Rvalue assignment.
void reset ()
 Clear all states. Removes loaded data so that the actual instance can be reused/refilled.
void reset (const Types &types)
 Clear all states.
void merge (const Dataset &other)
 Merge another Dataset.
void merge (const DbValues &row)
 Merge DbValues.
std::size_t getIndex (const std::string &name) const
 Get the index of a field by name.
void sort (const std::vector< size_t > &idxs, DbValueSort cmp=&dbval_lt)
 Sort the Dataset.
Public Member Functions inherited from sl3::Container< std::vector< DbValues > >
 Container () noexcept
 Constructor.
Containeroperator= (const Container &)=default
 Assignment.
virtual ~Container () noexcept(std::is_nothrow_destructible< std::vector< DbValues > >::value)=default
 Destructor.
iterator begin ()
 Iterator access.
iterator end ()
 Iterator access.
const_iterator cbegin () const
 Iterator access.
const_iterator cend () const
 Iterator access.
size_type size () const
 Container size.
reference at (size_t i)
 checked random access
reference operator[] (size_t i)
 unchecked random access

Additional Inherited Members

Protected Attributes inherited from sl3::Container< std::vector< DbValues > >
std::vector< DbValues_cont
 Container T.

Detailed Description

A utility for processing query results.

This class is a RowCallback that loads the result of a query into a list of DbValues. The loaded list can be browsed and the loaded values can be accessed.

A Dataset can either be created:

  • giving a DbValuesTypeList that describes the fields
    Giving a DbValuesTypeList the types of DbValue will use the given storage type when reading the data from sqlite.
    When the Dataset becomes populated with data the field count will be validated. In case the number of fields is different sl3::ErrTypeMisMatch will be thrown.
  • Without any specification
    In this case all fields will be DsVariantField, using the storage type sqlite reports for the actual value.

Member Typedef Documentation

◆ DbValueSort

typedef bool(* sl3::Dataset::DbValueSort) (const DbValue &, const DbValue &)

Typedef for a relation function signature.

Used to specify the less function that shall be used for sorting

a Dataset.

See also
Dataset::sort

Constructor & Destructor Documentation

◆ Dataset() [1/4]

sl3::Dataset::Dataset ( )
noexcept

Constructor.

All fields will be DsVariantField, using the storage type sqlite reports for the actual value. Field count will be detected and applied.

◆ Dataset() [2/4]

sl3::Dataset::Dataset ( Types types)

Constructor with DbValuesTypeList as description.

Types of DbValue will use the given description when creating the DbValue list. If the given list is not empty, field count will be validated when the actual instance becomes populated with data.

Parameters
typesTypes the fields must satisfy

◆ Dataset() [3/4]

sl3::Dataset::Dataset ( const Dataset & )
default

Copy Constructor.

◆ Dataset() [4/4]

sl3::Dataset::Dataset ( Dataset && ) const &&
noexcept

Move Constructor.

Member Function Documentation

◆ getIndex()

std::size_t sl3::Dataset::getIndex ( const std::string & name) const

Get the index of a field by name.

Exceptions
sl3::OutOfRangeif name is not found
Parameters
namefield name
Returns
field index

◆ merge() [1/2]

void sl3::Dataset::merge ( const Dataset & other)

Merge another Dataset.

Appends the data of the given Dataset to the end of the actual data. The field names and types of the given Dataset must match the current one.

Exceptions
sl3::ErrTypeMisMatchif field names types are not equal or size differs.
Parameters
otherDataset which shall be added to this one.

◆ merge() [2/2]

void sl3::Dataset::merge ( const DbValues & row)

Merge DbValues.

Appends the DbValues to the end of the actual data.

Exceptions
sl3::ErrTypeMisMatchif size differs from existing row size or if types are not compatible
Parameters
rowA row which shall be added.

◆ operator=() [1/2]

Dataset & sl3::Dataset::operator= ( const Dataset & )
default

Value assignment.

Returns
reference to this

◆ operator=() [2/2]

Dataset & sl3::Dataset::operator= ( Dataset && )
default

Rvalue assignment.

Returns
reference to this

◆ reset() [1/2]

void sl3::Dataset::reset ( )

Clear all states. Removes loaded data so that the actual instance can be reused/refilled.

◆ reset() [2/2]

void sl3::Dataset::reset ( const Types & types)

Clear all states.

Removes loaded data and sets a new specification for the field description so that the actual instance can be reused to populate with a different select statement / SQL command. Passing an empty DbValuesTypeList means that all fields will be DsVariantField and field count will be detected.

Parameters
typesnew Types requirement

◆ sort()

void sl3::Dataset::sort ( const std::vector< size_t > & idxs,
DbValueSort cmp = &dbval_lt )

Sort the Dataset.

Sort according to the given field indexes. The Dataset will be sorted according to sqlite rules.

Exceptions
sl3::OutOfRangeif a given index is invalid
Parameters
idxslist of field indexes
cmppointer to a less than compare function, default dbval_lt

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