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

A compiled SQL command. More...

#include <sl3/command.hpp>

Public Types

using Callback = std::function< bool(Columns)>
 function object for handling a command result. More...
 

Public Member Functions

 Command (Command &&)
 Move constructor. More...
 
 ~Command ()
 Destructor. More...
 
Dataset select ()
 Run the Command and get the result. More...
 
Dataset select (const DbValues &parameters, const Types &types={})
 Run the Command and get the result. More...
 
Dataset select (const Types &types, const DbValues &parameters={})
 Run the Command and get the result. More...
 
void execute ()
 Execute the command. More...
 
void execute (const DbValues &parameters)
 Execute the command. More...
 
void execute (RowCallback &cb, const DbValues &parameters={})
 Execute the command applying given callback. More...
 
void execute (Callback cb, const DbValues &parameters={})
 Execute the command applying given callback. More...
 
DbValuesgetParameters ()
 Parameters of command. More...
 
const DbValuesgetParameters () const
 Parameters of command. More...
 
DbValuegetParameter (int idx)
 get Parameter at given index. More...
 
const DbValuegetParameter (int idx) const
 get Parameter at given index. More...
 
void setParameters (const DbValues &values)
 Set parameter values. More...
 
void resetParameters (DbValues values)
 Set new parameter values. More...
 
std::vector< std::string > getParameterNames () const
 get a list of the parameter names More...
 

Detailed Description

A compiled SQL command.

This class holds a compiled SQL statement so that it can be reused.

A command can have parameters.

Member Typedef Documentation

◆ Callback

using sl3::Command::Callback = std::function<bool(Columns)>

function object for handling a command result.

Functor called for each processed row of Command or a sql statement.

Returns
false if processing the query result shall stop
true otherwise

Constructor & Destructor Documentation

◆ Command()

sl3::Command::Command ( Command &&  )

Move constructor.

A command is movable

◆ ~Command()

sl3::Command::~Command ( )

Destructor.

The destructor calls release.

Member Function Documentation

◆ execute() [1/4]

void sl3::Command::execute ( )

Execute the command.

Runs the current command. If parameters are set,

◆ execute() [2/4]

void sl3::Command::execute ( const DbValues parameters)

Execute the command.

Applies given parameters and run the current command.

Exceptions
sl3::ErrTypeMisMatchgiven parameters are of the wrong size.
Parameters
parametersa list of parameters

◆ execute() [3/4]

void sl3::Command::execute ( RowCallback cb,
const DbValues parameters = {} 
)

Execute the command applying given callback.

Applies given parameters and run the current command.

Exceptions
sl3::ErrTypeMisMatchgiven parameters are of the wrong size.
Parameters
cba callback
parametersa list of parameters

◆ execute() [4/4]

void sl3::Command::execute ( Callback  cb,
const DbValues parameters = {} 
)

Execute the command applying given callback.

Applies given parameters and run the current command.

Exceptions
sl3::ErrTypeMisMatchgiven parameters are of the wrong size.
Parameters
cba callback
parametersa list of parameters

◆ getParameter() [1/2]

DbValue& sl3::Command::getParameter ( int  idx)

get Parameter at given index.

Parameters
idxindex
Exceptions
sl3::ErrOutOfRangeif index is invalid
Returns
referenct to the parameters at given index

◆ getParameter() [2/2]

const DbValue& sl3::Command::getParameter ( int  idx) const

get Parameter at given index.

Parameters
idxindex
Exceptions
sl3::ErrOutOfRangeif index is invalid
Returns
const referenct to the parameters at given index

◆ getParameterNames()

std::vector<std::string> sl3::Command::getParameterNames ( ) const

get a list of the parameter names

If the command has no parameters, the list will be empty. Parameters with no name will be an empty entry in the list.

Returns
list of names

◆ getParameters() [1/2]

DbValues& sl3::Command::getParameters ( )

Parameters of command.

Returns
referenct to the parameters

◆ getParameters() [2/2]

const DbValues& sl3::Command::getParameters ( ) const

Parameters of command.

Returns
const referenct to the parameters

◆ resetParameters()

void sl3::Command::resetParameters ( DbValues  values)

Set new parameter values.

In contrast to setParameters, where the DbValue types must match, this can be used to set other Types.

Parameters
valuesnew parameter values
Exceptions
sl3::ErrTypeMisMatchif size of values differs from the actual one

◆ select() [1/3]

Dataset sl3::Command::select ( )

Run the Command and get the result.

Runs the command, applying possible already given parameters and returns the result in a Dataset.

Returns
A Dataset containing the query result

◆ select() [2/3]

Dataset sl3::Command::select ( const DbValues parameters,
const Types types = {} 
)

Run the Command and get the result.

Runs the command, applying given parameters and returns the result in a Dataset. It types are given, they are used for the returned Dataset. It no types are given all fields in the returned Dataset will be of Type::Variant

Exceptions
sl3::ErrTypeMisMatchif types are given which are invalid or given parameters are of the wrong size.
Parameters
parametersa list of parameters
typesTypes the Dataset shall use
Returns
A Dataset containing the query result

◆ select() [3/3]

Dataset sl3::Command::select ( const Types types,
const DbValues parameters = {} 
)

Run the Command and get the result.

Runs the command, applying possible given parameters and returns the result in a Dataset in which given types are used for the fields.

Exceptions
sl3::ErrTypeMisMatchif types are given which are invalid or given parameters are of the wrong size.
Parameters
parametersa list of parameters
typesTypes the Dataset shall use
Returns
A Dataset containing the query result

◆ setParameters()

void sl3::Command::setParameters ( const DbValues values)

Set parameter values.

The Types ot the given values must be compatible with the current ones.

Parameters
valuesnew paramter values
Exceptions
sl3::ErrTypeMisMatchif size of values differs from the actual parameter size or DbValue assignment throws.
See also
DbValue

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