SQLiteXX  0.1.0
 All Classes Namespaces Files Functions Enumerations Enumerator
Public Member Functions | List of all members
sqlite::statement Class Reference

Represents a single SQL statement that has been compiled into binary form and is ready to be evaluated, aka "sqlite3_stmt". More...

#include <Statement.h>

Inheritance diagram for sqlite::statement:
sqlite::reader< statement >

Public Member Functions

 statement () noexcept
 Default constructor. More...
 
template<typename... Values>
 statement (const dbconnection &connection, const std::string &text, Values &&...values)
 Creates, prepares, and binds values into an SQL statement. More...
 
template<typename... Values>
 statement (const dbconnection &connection, const std::u16string &text, Values &&...values)
 Creates, prepares, and binds values into an SQL statement. More...
 
 operator bool () const noexcept
 Used to specify if the statement object has a prepared SQLite statement. More...
 
sqlite3_stmt * handle () const noexcept
 Returns pointer to the underlying "sqlite3_stmt" object. More...
 
template<typename... Values>
void prepare (dbconnection const &connection, const std::string &text, Values &&...values)
 Turn an SQL query into byte code. More...
 
template<typename... Values>
void prepare (const dbconnection &connection, const std::u16string &text, Values &&...values)
 Turn an SQL query into byte code. More...
 
bool step () const
 Evaluates a prepared statement. More...
 
int execute () const
 Executes a prepared statement and will return the number of changes to the database. More...
 
void bind (const int index, const int value) const
 Binds an integer value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const double value) const
 Binds an double value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const void *const value, const int size, bindtype type=bindtype::transiently) const
 Binds an blob value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const blob &value) const
 Binds an blob value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const char *const value, const int size=-1, bindtype type=bindtype::transiently) const
 Binds an string value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const char16_t *const value, const int size=-1, bindtype type=bindtype::transiently) const
 Binds an UTF-16 string value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const std::string &value) const
 Binds an string value to a parameter in an SQL prepared statement. More...
 
void bind (const int index, const std::u16string &value) const
 Binds an UTF-16 string value to a parameter in an SQL prepared statement. More...
 
template<typename T >
void bind_name (const std::string &name, T &&value)
 Binds an value to a parameter in an SQL prepared statement. More...
 
template<typename... Values>
void bind_all (Values &&...values) const
 Binds values to parameters in an SQL prepared statement. More...
 
template<typename... Values>
void clear_bindings (Values &&...values) const
 Resets all SQL parameters to NULL. More...
 
void reset () const
 Resets a prepared statement object back to its initial state. More...
 
int get_int (const int column) const noexcept
 Returns the specified column value as an integer. More...
 
int get_int (const std::string &name) const noexcept
 Returns the specified column value as an integer. More...
 
int64_t get_int64 (const int column) const noexcept
 Returns the specified column value as a 64-bit integer. More...
 
int64_t get_int64 (const std::string &name) const noexcept
 Returns the specified column value as a 64-bit integer. More...
 
unsigned int get_uint (const int column) const noexcept
 Returns the specified column value as an unsigned integer. More...
 
unsigned int get_uint (const std::string &name) const noexcept
 Returns the specified column value as an unsigned integer. More...
 
double get_double (const int column) const noexcept
 Returns the specified column value as a double. More...
 
double get_double (const std::string &name) const noexcept
 Returns the specified column value as a double. More...
 
const blob get_blob (const int column) const noexcept
 Returns the specified column value as a blob object. More...
 
const blob get_blob (const std::string &name) const noexcept
 Returns the specified column value as a Blob object. More...
 
const std::string get_string (const int column) const noexcept
 Returns the specified column value as a string. More...
 
const std::string get_string (const std::string &name) const noexcept
 Returns the specified column value as a string. More...
 
const std::u16string get_u16string (const int column) const noexcept
 Returns the specified column value as a UTF-16 string. More...
 
const std::u16string get_u16string (const std::string &name) const noexcept
 Returns the specified column value as a UTF-16 string. More...
 
value get_value (const int column) const noexcept
 Returns the specified column value as a value object. More...
 
value get_value (const std::string &name) const
 Returns the specified column value as a value object. More...
 
int get_bytes (const int column) const noexcept
 Returns the size in bytes of the column value. More...
 
int get_bytes (const std::string &name) const noexcept
 Returns the size in bytes of the column value. More...
 
datatype get_type (const int column) const noexcept
 Returns the type of the specified column. More...
 
datatype get_type (const std::string &name) const noexcept
 Returns the type of the specified column. More...
 
int column_count () const noexcept
 Returns the number of columns in the result set returned by the prepared statement. More...
 
const char * get_column_name (const int index) const noexcept
 Returns the name assigned to a particular column. More...
 
const char16_t * get_column_wide_name (const int index) const noexcept
 Returns the name assigned to a particular column. More...
 
int get_column_index (const std::string &name) const
 Returns the position of a column with the specified name. More...
 

Detailed Description

Represents a single SQL statement that has been compiled into binary form and is ready to be evaluated, aka "sqlite3_stmt".

Definition at line 350 of file Statement.h.

Constructor & Destructor Documentation

sqlite::statement::statement ( )
noexcept

Default constructor.

Constructs an un-prepared statement object.

Definition at line 20 of file Statement.cpp.

template<typename... Values>
sqlite::statement::statement ( const dbconnection connection,
const std::string &  text,
Values &&...  values 
)
inline

Creates, prepares, and binds values into an SQL statement.

Parameters
[in]connectiona database connection to execute the statement on
[in]textthe SQL query
[in]valuespossible values to bind to SQL query if containing bind parameters

Definition at line 364 of file Statement.h.

template<typename... Values>
sqlite::statement::statement ( const dbconnection connection,
const std::u16string &  text,
Values &&...  values 
)
inline

Creates, prepares, and binds values into an SQL statement.

Parameters
[in]connectiona database connection to execute the statement on
[in]textUTF-16 encoded SQL query
[in]valuespossible values to bind to SQL query if containing bind parameters

Definition at line 381 of file Statement.h.

Member Function Documentation

void sqlite::statement::bind ( const int  index,
const int  value 
) const

Binds an integer value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.

Definition at line 68 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const double  value 
) const

Binds an double value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.

Definition at line 76 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const void *const  value,
const int  size,
bindtype  type = bindtype::transiently 
) const

Binds an blob value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.
[in]sizein bytes the size of the blob object
[in]typethe way to bind this parameter.

Definition at line 84 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const blob value 
) const

Binds an blob value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.

Definition at line 92 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const char *const  value,
const int  size = -1,
bindtype  type = bindtype::transiently 
) const

Binds an string value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.
[in]sizethe number of bytes of the value.
[in]typethe way to bind this parameter.

Definition at line 100 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const char16_t *const  value,
const int  size = -1,
bindtype  type = bindtype::transiently 
) const

Binds an UTF-16 string value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.
[in]sizethe number of bytes of the value.
[in]typethe way to bind this parameter.

Definition at line 108 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const std::string &  value 
) const

Binds an string value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.

Definition at line 116 of file Statement.cpp.

void sqlite::statement::bind ( const int  index,
const std::u16string &  value 
) const

Binds an UTF-16 string value to a parameter in an SQL prepared statement.

Parameters
[in]indexspecifies the index of the SQL parameter to be set
[in]valuethe value to bind to the parameter.

Definition at line 121 of file Statement.cpp.

template<typename... Values>
void sqlite::statement::bind_all ( Values &&...  values) const
inline

Binds values to parameters in an SQL prepared statement.

Parameters
[in]valuesthe values to bind to SQL parameters

Definition at line 511 of file Statement.h.

template<typename T >
void sqlite::statement::bind_name ( const std::string &  name,
T &&  value 
)
inline

Binds an value to a parameter in an SQL prepared statement.

Parameters
[in]namespecifies the name of the SQL parameter to be set
[in]valuethe value to bind to the parameter.

Definition at line 501 of file Statement.h.

template<typename... Values>
void sqlite::statement::clear_bindings ( Values &&...  values) const
inline

Resets all SQL parameters to NULL.

Parameters
[in]valuesPossible values to to bind to SQL parameters.

Definition at line 520 of file Statement.h.

int sqlite::reader< statement >::column_count ( ) const
inlinenoexceptinherited

Returns the number of columns in the result set returned by the prepared statement.

If this method returns 0, that means the prepared statment returns no data (for example an UPDATE).

Returns
The number of columns in the result set.

Definition at line 234 of file Statement.h.

int sqlite::statement::execute ( ) const

Executes a prepared statement and will return the number of changes to the database.

Returns
The number of changes to the database.

Definition at line 57 of file Statement.cpp.

const blob sqlite::reader< statement >::get_blob ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as a blob object.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 116 of file Statement.h.

const blob sqlite::reader< statement >::get_blob ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as a Blob object.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 126 of file Statement.h.

int sqlite::reader< statement >::get_bytes ( const int  column) const
inlinenoexceptinherited

Returns the size in bytes of the column value.

Parameters
[in]columnposition of the column to return
Returns
the size in bytes of the column value

Definition at line 196 of file Statement.h.

int sqlite::reader< statement >::get_bytes ( const std::string &  name) const
inlinenoexceptinherited

Returns the size in bytes of the column value.

Parameters
[in]namename of the column to return
Returns
the size in bytes of the column value

Definition at line 205 of file Statement.h.

int sqlite::reader< statement >::get_column_index ( const std::string &  name) const
inlineinherited

Returns the position of a column with the specified name.

Returns
The position of the column
Exceptions
SQLiteXXExceptionif no column with specified name was found

Definition at line 261 of file Statement.h.

const char* sqlite::reader< statement >::get_column_name ( const int  index) const
inlinenoexceptinherited

Returns the name assigned to a particular column.

Parameters
[in]indexthe position of the column
Returns
The name of the specified column.

Definition at line 243 of file Statement.h.

const char16_t* sqlite::reader< statement >::get_column_wide_name ( const int  index) const
inlinenoexceptinherited

Returns the name assigned to a particular column.

Parameters
[in]indexthe position of the column
Returns
The name of the specified column.

Definition at line 252 of file Statement.h.

double sqlite::reader< statement >::get_double ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as a double.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 97 of file Statement.h.

double sqlite::reader< statement >::get_double ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as a double.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 106 of file Statement.h.

int sqlite::reader< statement >::get_int ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as an integer.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 40 of file Statement.h.

int sqlite::reader< statement >::get_int ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as an integer.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 49 of file Statement.h.

int64_t sqlite::reader< statement >::get_int64 ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as a 64-bit integer.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 59 of file Statement.h.

int64_t sqlite::reader< statement >::get_int64 ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as a 64-bit integer.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 68 of file Statement.h.

const std::string sqlite::reader< statement >::get_string ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as a string.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 136 of file Statement.h.

const std::string sqlite::reader< statement >::get_string ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as a string.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 146 of file Statement.h.

datatype sqlite::reader< statement >::get_type ( const int  column) const
inlinenoexceptinherited

Returns the type of the specified column.

Parameters
[in]columnposition of the column to return
Returns
The sqlite::datatype value for a column

Definition at line 215 of file Statement.h.

datatype sqlite::reader< statement >::get_type ( const std::string &  name) const
inlinenoexceptinherited

Returns the type of the specified column.

Parameters
[in]namename of the column to return
Returns
The sqlite::datatype value for a column

Definition at line 224 of file Statement.h.

const std::u16string sqlite::reader< statement >::get_u16string ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as a UTF-16 string.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 156 of file Statement.h.

const std::u16string sqlite::reader< statement >::get_u16string ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as a UTF-16 string.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 166 of file Statement.h.

unsigned int sqlite::reader< statement >::get_uint ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as an unsigned integer.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 78 of file Statement.h.

unsigned int sqlite::reader< statement >::get_uint ( const std::string &  name) const
inlinenoexceptinherited

Returns the specified column value as an unsigned integer.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 87 of file Statement.h.

value sqlite::reader< statement >::get_value ( const int  column) const
inlinenoexceptinherited

Returns the specified column value as a value object.

Parameters
[in]columnposition of the column to return
Returns
value of column as integer

Definition at line 176 of file Statement.h.

value sqlite::reader< statement >::get_value ( const std::string &  name) const
inlineinherited

Returns the specified column value as a value object.

Parameters
[in]namename of the column to return
Returns
value of column as integer

Definition at line 185 of file Statement.h.

sqlite3_stmt * sqlite::statement::handle ( ) const
noexcept

Returns pointer to the underlying "sqlite3_stmt" object.

The returned sqlite3_stmt object pointer will be automatically deleted on the destruction of the parent statement object.

Definition at line 32 of file Statement.cpp.

sqlite::statement::operator bool ( ) const
noexcept

Used to specify if the statement object has a prepared SQLite statement.

Returns
The returns true if the statement object has been assigned a SQLite prepared statement.

Definition at line 25 of file Statement.cpp.

template<typename... Values>
void sqlite::statement::prepare ( dbconnection const &  connection,
const std::string &  text,
Values &&...  values 
)
inline

Turn an SQL query into byte code.

Parameters
[in]connectiona successfully opened database connection
[in]textthe statement to be compiled, encoded as UTF-8
[in]valuespossible bindings

Definition at line 408 of file Statement.h.

template<typename... Values>
void sqlite::statement::prepare ( const dbconnection connection,
const std::u16string &  text,
Values &&...  values 
)
inline

Turn an SQL query into byte code.

Parameters
[in]connectiona successfully opened database connection
[in]textthe statement to be compiled, encoded as UTF-16
[in]valuespossible bindings

Definition at line 422 of file Statement.h.

void sqlite::statement::reset ( ) const
inline

Resets a prepared statement object back to its initial state.

Any SQL statment parameters that had values bound to them using the bind method return their values. Use clearBindings to reset the bindings.

Definition at line 535 of file Statement.h.

bool sqlite::statement::step ( ) const

Evaluates a prepared statement.

This method can be called one or more times to evaluate the statement.

Returns
true when there are more rows to iterate through and false when there are no more
Exceptions
sqlite::exceptionor a derived class

Definition at line 37 of file Statement.cpp.


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