sqlitepp
C++ binding for the SQLite3 library
Public Member Functions | Friends | List of all members
sqlitepp::Statement Class Reference

A handle for a SQLite3 statement. More...

#include <sqlitepp/sqlitepp.h>

Inheritance diagram for sqlitepp::Statement:
Inheritance graph
[legend]
Collaboration diagram for sqlitepp::Statement:
Collaboration graph
[legend]

Public Member Functions

 ~Statement ()
 Deconstructs this object and finalizes the statement. More...
 
void bind (const int index, const double value)
 Binds the given double value to the column with the given index. More...
 
void bind (const std::string &name, const double value)
 Binds the given double value to the column with the given name. More...
 
void bind (const int index, const int value)
 Binds the given integer value to the column with the given index. More...
 
void bind (const std::string &name, const int value)
 Binds the given integer value to the column with the given name. More...
 
void bind (const int index, const std::string &value)
 Binds the given string value to the column with the given index. More...
 
void bind (const std::string &name, const std::string &value)
 Binds the given string value to the column with the given name. More...
 
void close ()
 Closes this statement. More...
 
ResultSet execute ()
 Executes this statement and returns the result (if any). More...
 
bool reset ()
 Resets the statement. More...
 
- Public Member Functions inherited from sqlitepp::Openable
bool isOpen () const
 Checks whether this object is open. More...
 

Friends

class Database
 
class ResultSet
 

Additional Inherited Members

- Protected Member Functions inherited from sqlitepp::Openable
 Openable (const bool open, const std::string &name)
 Creates a new Openable. More...
 
void requireOpen () const
 Requires this object to be open and throws an exception if it is not. More...
 
void setOpen (const bool open)
 Changes the state of this object. More...
 

Detailed Description

A handle for a SQLite3 statement.

This class stores a reference to a prepared SQLite3 statement and provides methods to bind parameters to the query, execute it and read the results. If a database operation fails, a DatabaseError is thrown.

Use Database::prepare to obtain instances of this class.

Constructor & Destructor Documentation

◆ ~Statement()

sqlitepp::Statement::~Statement ( )

Deconstructs this object and finalizes the statement.

Errors that occur when the statement is finalized are ignored as they already occured during the last operation.

Member Function Documentation

◆ bind() [1/6]

void sqlitepp::Statement::bind ( const int  index,
const double  value 
)

Binds the given double value to the column with the given index.

Parameters
indexthe index of the column to bind the value to
valuethe value to bind to that column
Exceptions
std::logic_errorif the statement is not open
std::out_of_rangeif the given index is out of range
std::runtime_errorif there is not enough memory to bind the value
DatabaseErrorif an database error occured during the binding

◆ bind() [2/6]

void sqlitepp::Statement::bind ( const std::string &  name,
const double  value 
)

Binds the given double value to the column with the given name.

Parameters
indexthe name of the column to bind the value to
valuethe value to bind to that column
Exceptions
std::logic_errorif the statement is not open
std::invalid_argumentif there is no column witht the given name
std::runtime_errorif there is not enough memory to bind the value
DatabaseErrorif an database error occured during the binding

◆ bind() [3/6]

void sqlitepp::Statement::bind ( const int  index,
const int  value 
)

Binds the given integer value to the column with the given index.

Parameters
indexthe index of the column to bind the value to
valuethe value to bind to that column
Exceptions
std::logic_errorif the statement is not open
std::out_of_rangeif the given index is out of range
std::runtime_errorif there is not enough memory to bind the value
DatabaseErrorif an database error occured during the binding

◆ bind() [4/6]

void sqlitepp::Statement::bind ( const std::string &  name,
const int  value 
)

Binds the given integer value to the column with the given name.

Parameters
indexthe name of the column to bind the value to
valuethe value to bind to that column
Exceptions
std::logic_errorif the statement is not open
std::invalid_argumentif there is no column witht the given name
std::runtime_errorif there is not enough memory to bind the value
DatabaseErrorif an database error occured during the binding

◆ bind() [5/6]

void sqlitepp::Statement::bind ( const int  index,
const std::string &  value 
)

Binds the given string value to the column with the given index.

Parameters
indexthe index of the column to bind the value to
valuethe value to bind to that column
Exceptions
std::logic_errorif the statement is not open
std::out_of_rangeif the given index is out of range
std::runtime_errorif there is not enough memory to bind the value
DatabaseErrorif an database error occured during the binding

◆ bind() [6/6]

void sqlitepp::Statement::bind ( const std::string &  name,
const std::string &  value 
)

Binds the given string value to the column with the given name.

Parameters
indexthe name of the column to bind the value to
valuethe value to bind to that column
Exceptions
std::logic_errorif the statement is not open
std::invalid_argumentif there is no column witht the given name
std::runtime_errorif there is not enough memory to bind the value
DatabaseErrorif an database error occured during the binding

◆ close()

void sqlitepp::Statement::close ( )

Closes this statement.

Once you closed this statement, you may no longer access it. Any errors that occur during finalization are ignored as they already occurred during the last operation.

◆ execute()

ResultSet sqlitepp::Statement::execute ( )

Executes this statement and returns the result (if any).

Returns
the result returned from the query (empty if there was no result)
Exceptions
std::logic_errorif the statement is not open
DatabaseErrorif a database error occurs during the query execution

◆ reset()

bool sqlitepp::Statement::reset ( )

Resets the statement.

Resets the statement so that it can be re-executed. Bindings are not resetted.

Returns
true if the reset was successful; otherwise false
Exceptions
std::logic_errorif the statement is not open

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