Sqlitepp  1.2.3
A thin sqlite C++ wrapper
Public Member Functions | List of all members
sqlite::Connection::Stmt Class Referencefinal

Prepared statement obj - usually created by Connection::create_statement. More...

#include <sqlite.hpp>

Public Member Functions

 Stmt (const std::string &sql, Connection &db)
 Prepare a new statement for the given SQL. More...
 
 Stmt (const Stmt &)=delete
 
Stmtoperator= (const Stmt &)=delete
 
 Stmt (Stmt &&)
 
Stmtoperator= (Stmt &&)
 
std::string bind_parameter_name (const int index)
 Get bind var name from index. More...
 
int bind_parameter_index (const std::string &name)
 Get bind var index by name. More...
 
int bind_parameter_count ()
 Get number of bind parameters. More...
 
bool step ()
 Run the statement. More...
 
template<typename T >
get_col (const int column)
 Get SELECTed column. More...
 
void reset ()
 Reset the statement. More...
 
void clear_bindings ()
 Clear all bind vars to NULL. More...
 
bool busy ()
 Determine if the statment has been reset. More...
 
bool readonly ()
 Determine if the statment is read-only. More...
 
const sqlite3_stmt * get_c_obj () const
 Get wrapped C sqlite3_stmt object (for use with the sqlite C API) More...
 
sqlite3_stmt * get_c_obj ()
 Get wrapped C sqlite3_stmt object (for use with the sqlite C API) More...
 
Bind functions

Functions for binding data to SQL statements

void bind (const int index, const double val)
 Bind var by index. More...
 
void bind (const int index, const int val)
 
void bind (const int index, const sqlite3_int64 val)
 
void bind (const int index, const std::string &val)
 
void bind (const int index, const char *val)
 
void bind_null (const int index)
 Bind null by index. More...
 
void bind (const int index)
 Bind null by index. More...
 
void bind (const std::string &name, const double val)
 Bind var by name. More...
 
void bind (const std::string &name, const int val)
 
void bind (const std::string &name, const sqlite3_int64 val)
 
void bind (const std::string &name, const std::string &val)
 
void bind (const std::string &name, const char *val)
 
void bind_null (const std::string &name)
 Bind null by name. More...
 
void bind (const std::string &name)
 Bind null by name. More...
 
Get columns

get_col() template specializations

template<>
double get_col (const int column)
 Get SELECTed column. More...
 
template<>
int get_col (const int column)
 Get SELECTed column. More...
 
template<>
sqlite3_int64 get_col (const int column)
 Get SELECTed column. More...
 
template<>
std::string get_col (const int column)
 Get SELECTed column. More...
 
template<>
const char * get_col (const int column)
 Get SELECTed column. More...
 

Detailed Description

Prepared statement obj - usually created by Connection::create_statement.

Data is bound to the statement with the bind() overloads, step() is called to execute the statement, and then get_col() can be used to retrieve rows from a SELECT statement.

When INSERTing or UPDATing multiple rows, call reset() to reuse the statement obj.

See also
C API

Constructor & Destructor Documentation

◆ Stmt()

sqlite::Connection::Stmt::Stmt ( const std::string &  sql,
Connection db 
)

Prepare a new statement for the given SQL.

It is usually easier to use Connection::create_statement instead of this

Parameters
[in]sqlSQL code to prepare
[in]dbDatabase Connection to prepare statement for
Exceptions
Logic_erroron error parsing SQL
See also
C API

Member Function Documentation

◆ bind() [1/12]

void sqlite::Connection::Stmt::bind ( const int  index,
const double  val 
)

Bind var by index.

Note
As in the sqlite C API, bind var indexes start at 1
Parameters
[in]indexBind variable index
[in]valBind variable value
Exceptions
Logic_erroron error binding
See also
C API

◆ bind() [2/12]

void sqlite::Connection::Stmt::bind ( const int  index,
const int  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind() [3/12]

void sqlite::Connection::Stmt::bind ( const int  index,
const sqlite3_int64  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind() [4/12]

void sqlite::Connection::Stmt::bind ( const int  index,
const std::string &  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind() [5/12]

void sqlite::Connection::Stmt::bind ( const int  index,
const char *  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind_null() [1/2]

void sqlite::Connection::Stmt::bind_null ( const int  index)

Bind null by index.

Note
As in the sqlite C API, bind var indexes start at 1
Parameters
[in]indexBind variable index
Exceptions
Logic_erroron error binding
See also
C API

◆ bind() [6/12]

void sqlite::Connection::Stmt::bind ( const int  index)

Bind null by index.

Note
As in the sqlite C API, bind var indexes start at 1
Parameters
[in]indexBind variable index
Exceptions
Logic_erroron error binding
See also
C API

◆ bind() [7/12]

void sqlite::Connection::Stmt::bind ( const std::string &  name,
const double  val 
)

Bind var by name.

Parameters
[in]nameBind variable name
[in]valBind variable value
Exceptions
Logic_erroron error binding
See also
C API

◆ bind() [8/12]

void sqlite::Connection::Stmt::bind ( const std::string &  name,
const int  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind() [9/12]

void sqlite::Connection::Stmt::bind ( const std::string &  name,
const sqlite3_int64  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind() [10/12]

void sqlite::Connection::Stmt::bind ( const std::string &  name,
const std::string &  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind() [11/12]

void sqlite::Connection::Stmt::bind ( const std::string &  name,
const char *  val 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ bind_null() [2/2]

void sqlite::Connection::Stmt::bind_null ( const std::string &  name)

Bind null by name.

Parameters
[in]nameBind variable name
Exceptions
Logic_erroron error binding
See also
C API

◆ bind() [12/12]

void sqlite::Connection::Stmt::bind ( const std::string &  name)

Bind null by name.

Parameters
[in]nameBind variable name
Exceptions
Logic_erroron error binding
See also
C API

◆ bind_parameter_name()

std::string sqlite::Connection::Stmt::bind_parameter_name ( const int  index)

Get bind var name from index.

Parameters
[in]indexBind variable index
Returns
Bind variable name
Exceptions
Logic_erroron error finding name
See also
C API

◆ bind_parameter_index()

int sqlite::Connection::Stmt::bind_parameter_index ( const std::string &  name)

Get bind var index by name.

Parameters
[in]nameBind variable name
Returns
Bind variable index
Exceptions
Logic_erroron error finding index
See also
C API

◆ bind_parameter_count()

int sqlite::Connection::Stmt::bind_parameter_count ( )

Get number of bind parameters.

Returns
Number of bind parameters
See also
C API

◆ step()

bool sqlite::Connection::Stmt::step ( )

Run the statement.

Returns
  • true on SELECT statements when more rows remain to be fetched
  • false for UPDATE, DELETE, or database commands, or when no more rows can be SELECTED
Exceptions
Logic_erroron error evaluating SQL
See also
C API

◆ get_col() [1/6]

template<typename T >
T sqlite::Connection::Stmt::get_col ( const int  column)

Get SELECTed column.

Parameters
[in]columnColumn number
  • Unlike bind() indexes, column indexes start at 0
Returns
Column data for the current row
Note
Only specific template types are allowed See documentation for template specializations.
See also
C API

◆ reset()

void sqlite::Connection::Stmt::reset ( )

Reset the statement.

Useful for inserting or updating multiple rows

Exceptions
Logic_erroron error resetting
See also
C API

◆ clear_bindings()

void sqlite::Connection::Stmt::clear_bindings ( )

Clear all bind vars to NULL.

See also
C API

◆ busy()

bool sqlite::Connection::Stmt::busy ( )

Determine if the statment has been reset.

Returns
true if the statement is busy (step has been called, but is not complete, nor reset)
See also
C API

◆ readonly()

bool sqlite::Connection::Stmt::readonly ( )

Determine if the statment is read-only.

Returns
true if the statement does not directly write to the DB
See also
C API

◆ get_c_obj() [1/2]

const sqlite3_stmt * sqlite::Connection::Stmt::get_c_obj ( ) const

Get wrapped C sqlite3_stmt object (for use with the sqlite C API)

Returns
C sqlite3_stmt object

◆ get_c_obj() [2/2]

sqlite3_stmt * sqlite::Connection::Stmt::get_c_obj ( )

Get wrapped C sqlite3_stmt object (for use with the sqlite C API)

Returns
C sqlite3_stmt object

◆ get_col() [2/6]

template<>
double sqlite::Connection::Stmt::get_col ( const int  column)

Get SELECTed column.

Parameters
[in]columnColumn number
  • Unlike bind() indexes, column indexes start at 0
Returns
Column data for the current row
Note
Only specific template types are allowed See documentation for template specializations.
See also
C API

◆ get_col() [3/6]

template<>
int sqlite::Connection::Stmt::get_col ( const int  column)

Get SELECTed column.

Parameters
[in]columnColumn number
  • Unlike bind() indexes, column indexes start at 0
Returns
Column data for the current row
Note
Only specific template types are allowed See documentation for template specializations.
See also
C API

◆ get_col() [4/6]

template<>
sqlite3_int64 sqlite::Connection::Stmt::get_col ( const int  column)

Get SELECTed column.

Parameters
[in]columnColumn number
  • Unlike bind() indexes, column indexes start at 0
Returns
Column data for the current row
Note
Only specific template types are allowed See documentation for template specializations.
See also
C API

◆ get_col() [5/6]

std::string get_col< std::string > ( const int  column)

Get SELECTed column.

Parameters
[in]columnColumn number
  • Unlike bind() indexes, column indexes start at 0
Returns
Column data for the current row
Note
Only specific template types are allowed See documentation for template specializations.
See also
C API

◆ get_col() [6/6]

template<>
const char* sqlite::Connection::Stmt::get_col ( const int  column)

Get SELECTed column.

Parameters
[in]columnColumn number
  • Unlike bind() indexes, column indexes start at 0
Returns
Column data for the current row
Note
Only specific template types are allowed See documentation for template specializations.
See also
C API

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