Kompex SQLite Wrapper  1.11.14
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Kompex::SQLiteStatement Class Reference

Execution of SQL statements and result processing. More...

#include <KompexSQLiteStatement.h>

Public Member Functions

 SQLiteStatement (SQLiteDatabase *db)
 
virtual ~SQLiteStatement ()
 Destructor. More...
 
void SqlStatement (const std::string &sqlStatement)
 
void SqlStatement (const char *sqlStatement)
 
void SqlStatement (const std::wstring &sqlStatement)
 
void SqlStatement (const wchar_t *sqlStatement)
 
void Sql (const std::string &sql)
 
void Sql (const char *sql)
 
void Sql (const std::wstring &sql)
 
void Sql (const wchar_t *sql)
 
bool FetchRow () const
 
void FreeQuery ()
 Call FreeQuery() after Sql(), Execute() and FetchRow() to clean-up. More...
 
float SqlAggregateFuncResult (const std::string &countSql)
 
float SqlAggregateFuncResult (wchar_t *countSql)
 
float SqlAggregateFuncResult (const char *countSql)
 
const char * GetColumnName (int column) const
 
const char * GetColumnName (const std::string &column) const
 
wchar_t * GetColumnName16 (int column) const
 
wchar_t * GetColumnName16 (const std::string &column) const
 
int GetColumnType (int column) const
 
int GetColumnType (const std::string &column) const
 
const unsigned char * GetColumnCString (int column) const
 
const unsigned char * GetColumnCString (const std::string &column) const
 
std::string GetColumnString (int column) const
 
std::string GetColumnString (const std::string &column) const
 
wchar_t * GetColumnString16 (int column) const
 
wchar_t * GetColumnString16 (const std::string &column) const
 
double GetColumnDouble (int column) const
 
double GetColumnDouble (const std::string &column) const
 
int GetColumnInt (int column) const
 
int GetColumnInt (const std::string &column) const
 
bool GetColumnBool (int column) const
 
bool GetColumnBool (const std::string &column) const
 
int64 GetColumnInt64 (int column) const
 
int64 GetColumnInt64 (const std::string &column) const
 
const void * GetColumnBlob (int column) const
 
const void * GetColumnBlob (const std::string &column) const
 
int GetColumnBytes (int column) const
 
int GetColumnBytes (const std::string &column) const
 
int GetColumnBytes16 (int column) const
 
int GetColumnBytes16 (const std::string &column) const
 
const char * GetColumnDatabaseName (int column) const
 
const char * GetColumnDatabaseName (const std::string &column) const
 
wchar_t * GetColumnDatabaseName16 (int column) const
 
wchar_t * GetColumnDatabaseName16 (const std::string &column) const
 
const char * GetColumnTableName (int column) const
 
const char * GetColumnTableName (const std::string &column) const
 
wchar_t * GetColumnTableName16 (int column) const
 
wchar_t * GetColumnTableName16 (const std::string &column) const
 
const char * GetColumnOriginName (int column) const
 
const char * GetColumnOriginName (const std::string &column) const
 
wchar_t * GetColumnOriginName16 (int column) const
 
wchar_t * GetColumnOriginName16 (const std::string &column) const
 
const char * GetColumnDeclaredDatatype (int column) const
 
const char * GetColumnDeclaredDatatype (const std::string &column) const
 
wchar_t * GetColumnDeclaredDatatype16 (int column) const
 
wchar_t * GetColumnDeclaredDatatype16 (const std::string &column) const
 
int GetColumnCount () const
 
int GetDataCount () const
 
void BindInt (int column, int value) const
 
void BindBool (int column, bool value) const
 
void BindString (int column, const std::string &string) const
 
void BindString16 (int column, const wchar_t *string) const
 
void BindString64 (int column, const char *string, uint64 byteLength, ENCODING encoding) const
 
void BindDouble (int column, double value) const
 
void BindInt64 (int column, int64 value) const
 
void BindNull (int column) const
 
void BindBlob (int column, const void *data, int numberOfBytes=-1) const
 
void BindBlob64 (int column, const void *data, uint64 numberOfBytes=-1) const
 
void BindZeroBlob (int column, int length) const
 
void BindZeroBlob64 (int column, uint64 length) const
 
void Execute () const
 
void ExecuteAndFree ()
 
void GetTable (const std::string &sql, unsigned short consoleOutputColumnWidth=20) const
 
void GetTableColumnMetadata (const std::string &tableName, const std::string &columnName) const
 
void ClearBindings () const
 
void Reset () const
 
void BeginTransaction ()
 Begins a transaction. More...
 
void CommitTransaction ()
 
void RollbackTransaction ()
 Rollback a transaction. More...
 
void Transaction (const char *sql)
 
void Transaction (const std::string &sql)
 
void Transaction (const wchar_t *sql)
 
void SecureTransaction (const char *sql)
 
void SecureTransaction (const std::string sql)
 
void SecureTransaction (const wchar_t *sql)
 
std::string GetSqlResultString (const std::string &sql, const std::string &defaultReturnValue="")
 
std::string GetSqlResultString (const char *sql, const std::string &defaultReturnValue="")
 
std::string GetSqlResultString (const wchar_t *sql, const std::string &defaultReturnValue="")
 
int GetSqlResultInt (const std::string &sql, int defaultReturnValue=-1)
 
int GetSqlResultInt (const char *sql, int defaultReturnValue=-1)
 
int GetSqlResultInt (const wchar_t *sql, int defaultReturnValue=-1)
 
int64 GetSqlResultInt64 (const std::string &sql, int64 defaultReturnValue=-1)
 
int64 GetSqlResultInt64 (const char *sql, int64 defaultReturnValue=-1)
 
int64 GetSqlResultInt64 (const wchar_t *sql, int64 defaultReturnValue=-1)
 
double GetSqlResultDouble (const std::string &sql, double defaultReturnValue=-1)
 
double GetSqlResultDouble (const char *sql, double defaultReturnValue=-1)
 
double GetSqlResultDouble (const wchar_t *sql, double defaultReturnValue=-1)
 
const unsigned char * GetSqlResultCString (const std::string &sql, const unsigned char *defaultReturnValue=0)
 
const unsigned char * GetSqlResultCString (const char *sql, const unsigned char *defaultReturnValue=0)
 
const unsigned char * GetSqlResultCString (const wchar_t *sql, const unsigned char *defaultReturnValue=0)
 
wchar_t * GetSqlResultString16 (const std::string &sql, wchar_t *defaultReturnValue=0)
 
wchar_t * GetSqlResultString16 (const char *sql, wchar_t *defaultReturnValue=0)
 
wchar_t * GetSqlResultString16 (const wchar_t *sql, wchar_t *defaultReturnValue=0)
 
const void * GetSqlResultBlob (const std::string &sql, const void *defaultReturnValue=0)
 
const void * GetSqlResultBlob (const char *sql, const void *defaultReturnValue=0)
 
const void * GetSqlResultBlob (const wchar_t *sql, const void *defaultReturnValue=0)
 
unsigned int GetNumberOfRows ()
 

Static Public Member Functions

static std::string Mprintf (const char *sql,...)
 
static std::string Vmprintf (const char *sql, va_list args)
 

Protected Member Functions

void Prepare (const char *sqlStatement)
 
void Prepare (const wchar_t *sqlStatement)
 
bool Step () const
 Must be called one or more times to evaluate the statement. More...
 
void CheckStatement () const
 Checks if the statement pointer is valid. More...
 
void CheckDatabase () const
 Checks if the database pointer is valid. More...
 
sqlite3_stmt * GetStatementHandle () const
 Returns the SQLite statement handle. More...
 
const unsigned char * SqlResultCString (const unsigned char *defaultReturnValue)
 Returns the first value of the first row. Internally used in GetSqlResultCString(). More...
 
wchar_t * SqlResultString16 (wchar_t *defaultReturnValue)
 Returns the first value of the first row. Internally used in GetSqlResultString16(). More...
 
const void * SqlResultBlob (const void *defaultReturnValue)
 Returns the first value of the first row. Internally used in GetSqlResultBlob(). More...
 
void CheckColumnNumber (int columnNumber, const std::string &functionName="") const
 
void CleanUpTransaction ()
 Free the allocated memory and clean the containers. More...
 
template<class T >
void DeleteTransactionSqlStr (bool isMemAllocated, T *str)
 
template<class S , class T >
GetColumnValue (S sql, T(Kompex::SQLiteStatement::*getColumnFunc)(int columnNumber) const, T defaultReturnValue)
 

Private Types

typedef std::map< unsigned short, std::pair< const char *, bool > > TTransactionSQL
 typedef for UTF-8 transaction statements More...
 
typedef std::map< unsigned short, std::pair< const wchar_t *, bool > > TTransactionSQL16
 typedef for UTF-16 transaction statements More...
 

Private Member Functions

void AssignColumnNumberToColumnName () const
 Assigns to every column number the corresponding column name. More...
 
int GetAssignedColumnNumber (const std::string &columnName) const
 Returns the column number for a given column name. More...
 

Private Attributes

struct sqlite3_stmt * mStatement
 SQL statement. More...
 
SQLiteDatabasemDatabase
 Database pointer. More...
 
TTransactionSQL mTransactionSQL
 Stores UTF-8 transaction statements. More...
 
TTransactionSQL16 mTransactionSQL16
 Stores UTF-16 transaction statements. More...
 
unsigned short mTransactionID
 ID for transactions. More...
 
std::map< std::string, int > mColumnNumberToColumnNameAssignment
 Container which stores the assignments for every column number and the corresponding column name (cache the results). More...
 
bool mIsColumnNumberAssignedToColumnName
 Saves whether the assignments for every column number and the corresponding column name was already done. More...
 

Detailed Description

Execution of SQL statements and result processing.

Member Typedef Documentation

typedef std::map<unsigned short , std::pair<const char* , bool > > Kompex::SQLiteStatement::TTransactionSQL
private

typedef for UTF-8 transaction statements

typedef std::map<unsigned short , std::pair<const wchar_t* , bool > > Kompex::SQLiteStatement::TTransactionSQL16
private

typedef for UTF-16 transaction statements

Constructor & Destructor Documentation

Kompex::SQLiteStatement::SQLiteStatement ( SQLiteDatabase db)

Constructor.

Parameters
dbDatabase in which the SQL should be performed
Kompex::SQLiteStatement::~SQLiteStatement ( )
virtual

Destructor.

Member Function Documentation

void Kompex::SQLiteStatement::AssignColumnNumberToColumnName ( ) const
private

Assigns to every column number the corresponding column name.

void Kompex::SQLiteStatement::BeginTransaction ( )

Begins a transaction.

void Kompex::SQLiteStatement::BindBlob ( int  column,
const void *  data,
int  numberOfBytes = -1 
) const

Overrides prior binding on the same parameter with a BLOB.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
dataBLOB data which should inserted in the indicated column
numberOfBytesThe size of the second parameter (const void *data) in bytes.
Please pay attention, that numberOfBytes is not the number of characters! Default: -1.
Negative numberOfBytes means, that the length of the string is the number of
bytes up to the first zero terminator.
void Kompex::SQLiteStatement::BindBlob64 ( int  column,
const void *  data,
uint64  numberOfBytes = -1 
) const

Overrides prior binding on the same parameter with a BLOB.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
dataBLOB data which should inserted in the indicated column
numberOfBytesThe size of the second parameter (const void *data) in bytes.
In contrast to BindBlob() this method supports a 64-bit length.
Please pay attention, that numberOfBytes is not the number of characters! Default: -1.
Negative numberOfBytes means, that the length of the string is the number of
bytes up to the first zero terminator.
void Kompex::SQLiteStatement::BindBool ( int  column,
bool  value 
) const

Overrides prior binding on the same parameter with an bool value.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
valuebool which should be inserted in the indicated column
void Kompex::SQLiteStatement::BindDouble ( int  column,
double  value 
) const

Overrides prior binding on the same parameter with a double value.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
valuedouble value which should be inserted in the indicated column
void Kompex::SQLiteStatement::BindInt ( int  column,
int  value 
) const

Overrides prior binding on the same parameter with an int value.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
valueint value which should be inserted in the indicated column
void Kompex::SQLiteStatement::BindInt64 ( int  column,
int64  value 
) const

Overrides prior binding on the same parameter with an int64 value.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
valueint64 value which should be inserted in the indicated column
void Kompex::SQLiteStatement::BindNull ( int  column) const

Overrides prior binding on the same parameter with NULL.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
void Kompex::SQLiteStatement::BindString ( int  column,
const std::string &  string 
) const

Overrides prior binding on the same parameter with an UTF-8 string.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
stringUTF-8 string which should be inserted in the indicated column
void Kompex::SQLiteStatement::BindString16 ( int  column,
const wchar_t *  string 
) const

Overrides prior binding on the same parameter with an UTF-16 string.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
stringUTF-16 string which should be inserted in the indicated column
void Kompex::SQLiteStatement::BindString64 ( int  column,
const char *  string,
uint64  byteLength,
ENCODING  encoding 
) const

Overrides prior binding on the same parameter with an UTF8, UTF16LE, UTF16BE, UTF16 or UTF16_ALIGNED string.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
stringUTF8, UTF16LE, UTF16BE, UTF16 or UTF16_ALIGNED string which should be inserted in the indicated column
byteLengthSize of the string in bytes.
encodingKompex::UTF8, Kompex::UTF16LE, Kompex::UTF16BE, Kompex::UTF16 (native byte order) or Kompex::UTF16_ALIGNED (sqlite3_create_collation only)
void Kompex::SQLiteStatement::BindZeroBlob ( int  column,
int  length 
) const

Overrides prior binding on the same parameter with a blob that is filled with zeroes.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
lengthlength of BLOB, which is filled with zeroes
void Kompex::SQLiteStatement::BindZeroBlob64 ( int  column,
uint64  length 
) const

Overrides prior binding on the same parameter with a blob that is filled with zeroes.
You must call Sql() one time, before you can use Bind..() methods!

Parameters
columnColumn, in which the data should be inserted
lengthLength of BLOB, which is filled with zeroes.
In contrast to BindZeroBlob() this method supports a 64-bit length.
void Kompex::SQLiteStatement::CheckColumnNumber ( int  columnNumber,
const std::string &  functionName = "" 
) const
protected

Checks whether the given column number is located within the available column range.

Parameters
columnNumbercolumn number which shall be checked
functionNamename of the function which shall be shown in the exception message
void Kompex::SQLiteStatement::CheckDatabase ( ) const
protected

Checks if the database pointer is valid.

void Kompex::SQLiteStatement::CheckStatement ( ) const
protected

Checks if the statement pointer is valid.

void Kompex::SQLiteStatement::CleanUpTransaction ( )
protected

Free the allocated memory and clean the containers.

void Kompex::SQLiteStatement::ClearBindings ( ) const

Resets all SQL parameter bindings back to NULL.
ClearBindings() does not reset the bindings on a prepared statement!

void Kompex::SQLiteStatement::CommitTransaction ( )

Commits a transaction.
Exception output: std::cerr

template<class T >
void Kompex::SQLiteStatement::DeleteTransactionSqlStr ( bool  isMemAllocated,
T *  str 
)
inlineprotected

Free the allocated memory of sql statements

Parameters
isMemAllocatedWas memory allocated?
strSQL statement string
void Kompex::SQLiteStatement::Execute ( ) const

Executes a prepared statement and doesn't clean-up so that you can reuse the prepared statement.
You must first call Sql() and Bind..() methods!
After you executed the prepared statement while calling Execute() you must call Reset() afterwards
so that the previous bindings will be removed. After this you can bind values with Bind() again.
Don't forget to call FreeQuery() to clean-up if you have finsihed your work.

void Kompex::SQLiteStatement::ExecuteAndFree ( )

Executes a prepared statement and clean-up.
You must first call Sql() and Bind..() methods!

bool Kompex::SQLiteStatement::FetchRow ( ) const

If you have called Sql(), you can step throw all results.

Returns
'true' if there are further result rows and 'false' if there is no further result row
void Kompex::SQLiteStatement::FreeQuery ( )

Call FreeQuery() after Sql(), Execute() and FetchRow() to clean-up.

int Kompex::SQLiteStatement::GetAssignedColumnNumber ( const std::string &  columnName) const
private

Returns the column number for a given column name.

const void * Kompex::SQLiteStatement::GetColumnBlob ( int  column) const

Returns a void* from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
const void * Kompex::SQLiteStatement::GetColumnBlob ( const std::string &  column) const

Returns a void* from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
bool Kompex::SQLiteStatement::GetColumnBool ( int  column) const

Returns a bool from a single column of the current result row of a query.
You must first call Sql()!
Please note that GetColumnBool() will also return "false" if you use
SqlStatement() with 'true' or 'false' as value for a bool column. Please use 1 (true)
or 0 (false) as bool value because sqlite doesn't know the key words 'true' and 'false'.

Parameters
columnNumber of the column from which we want to read the data.
bool Kompex::SQLiteStatement::GetColumnBool ( const std::string &  column) const

Returns a bool from a single column of the current result row of a query.
You must first call Sql()!
Please note that GetColumnBool() will also return "false" if you use
SqlStatement() with 'true' or 'false' as value for a bool column. Please use 1 (true)
or 0 (false) as bool value because sqlite doesn't know the key words 'true' and 'false'.

Parameters
columnName of the column from which we want to read the data.
int Kompex::SQLiteStatement::GetColumnBytes ( int  column) const

Returns the number of bytes in a column that has type BLOB or the number of bytes in a TEXT string with UTF-8 encoding.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the bytes.
int Kompex::SQLiteStatement::GetColumnBytes ( const std::string &  column) const

Returns the same value for BLOBs but for TEXT strings returns the number of bytes in a UTF-16 encoding.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the bytes.
int Kompex::SQLiteStatement::GetColumnBytes16 ( int  column) const

Returns the same value for BLOBs but for TEXT strings returns the number of bytes in a UTF-16 encoding.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the bytes.
int Kompex::SQLiteStatement::GetColumnBytes16 ( const std::string &  column) const

Returns the same value for BLOBs but for TEXT strings returns the number of bytes in a UTF-16 encoding.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the bytes.
int Kompex::SQLiteStatement::GetColumnCount ( ) const

Return the number of columns in the result set.
You must first call Sql()!

const unsigned char * Kompex::SQLiteStatement::GetColumnCString ( int  column) const

Returns a character-string from a single column of the current result row of a query.
NULL values will be returned as null pointer.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
const unsigned char * Kompex::SQLiteStatement::GetColumnCString ( const std::string &  column) const

Returns a character-string from a single column of the current result row of a query.
NULL values will be returned as null pointer.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
const char * Kompex::SQLiteStatement::GetColumnDatabaseName ( int  column) const

Returns a UTF-8 zero-terminated name of the database.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the database name.
const char * Kompex::SQLiteStatement::GetColumnDatabaseName ( const std::string &  column) const

Returns a UTF-8 zero-terminated name of the database.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the database name.
wchar_t * Kompex::SQLiteStatement::GetColumnDatabaseName16 ( int  column) const

Returns a UTF-16 zero-terminated name of the database.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the database name.
wchar_t * Kompex::SQLiteStatement::GetColumnDatabaseName16 ( const std::string &  column) const

Returns a UTF-8 zero-terminated name of the database.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the database name.
const char * Kompex::SQLiteStatement::GetColumnDeclaredDatatype ( int  column) const

Returns a zero-terminated UTF-8 string containing the declared datatype of the table column.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the declared datatype of the table column.
const char * Kompex::SQLiteStatement::GetColumnDeclaredDatatype ( const std::string &  column) const

Returns a zero-terminated UTF-8 string containing the declared datatype of the table column.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the declared datatype of the table column.
wchar_t * Kompex::SQLiteStatement::GetColumnDeclaredDatatype16 ( int  column) const

Returns a zero-terminated UTF-16 string containing the declared datatype of the table column.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the declared datatype of the table column.
wchar_t * Kompex::SQLiteStatement::GetColumnDeclaredDatatype16 ( const std::string &  column) const

Returns a zero-terminated UTF-8 string containing the declared datatype of the table column.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the declared datatype of the table column.
double Kompex::SQLiteStatement::GetColumnDouble ( int  column) const

Returns a double from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
double Kompex::SQLiteStatement::GetColumnDouble ( const std::string &  column) const

Returns a double from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
int Kompex::SQLiteStatement::GetColumnInt ( int  column) const

Returns a int from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
int Kompex::SQLiteStatement::GetColumnInt ( const std::string &  column) const

Returns a int from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
int64 Kompex::SQLiteStatement::GetColumnInt64 ( int  column) const

Returns a int64 from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
int64 Kompex::SQLiteStatement::GetColumnInt64 ( const std::string &  column) const

Returns a int64 from a single column of the current result row of a query.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
const char * Kompex::SQLiteStatement::GetColumnName ( int  column) const

Returns the name (UTF-8) assigned to a particular column in the result set of a SELECT statement.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the column name.
const char * Kompex::SQLiteStatement::GetColumnName ( const std::string &  column) const

Returns the name (UTF-8) assigned to a particular column in the result set of a SELECT statement.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the column name.
wchar_t * Kompex::SQLiteStatement::GetColumnName16 ( int  column) const

Returns the name (UTF-16) assigned to a particular column in the result set of a SELECT statement.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the column name.
wchar_t * Kompex::SQLiteStatement::GetColumnName16 ( const std::string &  column) const

Returns the name (UTF-16) assigned to a particular column in the result set of a SELECT statement.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the column name.
const char * Kompex::SQLiteStatement::GetColumnOriginName ( int  column) const

Returns a UTF-8 zero-terminated name of the table column.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the table column name.
const char * Kompex::SQLiteStatement::GetColumnOriginName ( const std::string &  column) const

Returns a UTF-8 zero-terminated name of the table column.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the table column name.
wchar_t * Kompex::SQLiteStatement::GetColumnOriginName16 ( int  column) const

Returns a UTF-16 zero-terminated name of the table column.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the table column name.
wchar_t * Kompex::SQLiteStatement::GetColumnOriginName16 ( const std::string &  column) const

Returns a UTF-8 zero-terminated name of the table column.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the table column name.
std::string Kompex::SQLiteStatement::GetColumnString ( int  column) const

Returns a std::string from a single column of the current result row of a query.
NULL values will be represented as an empty string [std::string("")].
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
std::string Kompex::SQLiteStatement::GetColumnString ( const std::string &  column) const

Returns a std::string from a single column of the current result row of a query.
NULL values will be represented as an empty string [std::string("")].
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
wchar_t * Kompex::SQLiteStatement::GetColumnString16 ( int  column) const

Returns a UTF-16 string from a single column of the current result row of a query.
NULL values will be returned as null pointer.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the data.
wchar_t * Kompex::SQLiteStatement::GetColumnString16 ( const std::string &  column) const

Returns a UTF-16 string from a single column of the current result row of a query.
NULL values will be returned as null pointer.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the data.
const char * Kompex::SQLiteStatement::GetColumnTableName ( int  column) const

Returns a UTF-8 zero-terminated name of the table.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the table name.
const char * Kompex::SQLiteStatement::GetColumnTableName ( const std::string &  column) const

Returns a UTF-8 zero-terminated name of the table.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the table name.
wchar_t * Kompex::SQLiteStatement::GetColumnTableName16 ( int  column) const

Returns a UTF-16 zero-terminated name of the table.
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the table name.
wchar_t * Kompex::SQLiteStatement::GetColumnTableName16 ( const std::string &  column) const

Returns a UTF-8 zero-terminated name of the table.
You must first call Sql()!

Parameters
columnName of the column from which we want to read the table name.
int Kompex::SQLiteStatement::GetColumnType ( int  column) const

Returns the datatype code for the initial data type of the result column.
SQLITE_INTEGER 1
SQLITE_FLOAT 2
SQLITE_TEXT 3
SQLITE3_TEXT 3
SQLITE_BLOB 4
SQLITE_NULL 5
You must first call Sql()!

Parameters
columnNumber of the column from which we want to read the column type.
int Kompex::SQLiteStatement::GetColumnType ( const std::string &  column) const

Returns the datatype code for the initial data type of the result column.
SQLITE_INTEGER 1
SQLITE_FLOAT 2
SQLITE_TEXT 3
SQLITE3_TEXT 3
SQLITE_BLOB 4
SQLITE_NULL 5
You must first call Sql()!

Parameters
columnName of the column from which we want to read the column type.
template<class S , class T >
T Kompex::SQLiteStatement::GetColumnValue ( sql,
T(Kompex::SQLiteStatement::*)(int columnNumber) const  getColumnFunc,
defaultReturnValue 
)
protected

Returns the first value of the first row from the given sql statement result.

Parameters
sqlSQL statement
getColumnFuncFunction to get the SQL statement result
defaultReturnValueDefault return value when the SQL statement has no result
int Kompex::SQLiteStatement::GetDataCount ( ) const
inline

Returns the number of values in the current row of the result set.
You must first call Sql()!

unsigned int Kompex::SQLiteStatement::GetNumberOfRows ( )

If you call this function directly after you called the Sql() function then you will get
the total number of returned rows. If you call this function after you already requested data from the
result then you will get the number of the remaining rows. Please note that the prepared statement will
be reset. Therefore, you would request the data of the first result row after you called this function.

const void * Kompex::SQLiteStatement::GetSqlResultBlob ( const std::string &  sql,
const void *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
const void *myValue = GetSqlResultBlob("SELECT picture FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
const void * Kompex::SQLiteStatement::GetSqlResultBlob ( const char *  sql,
const void *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
const void *myValue = GetSqlResultBlob("SELECT picture FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
const void * Kompex::SQLiteStatement::GetSqlResultBlob ( const wchar_t *  sql,
const void *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
const void *myValue = GetSqlResultBlob("SELECT picture FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
const unsigned char * Kompex::SQLiteStatement::GetSqlResultCString ( const std::string &  sql,
const unsigned char *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
const unsigned char *myValue = GetSqlResultCString("SELECT name FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
const unsigned char * Kompex::SQLiteStatement::GetSqlResultCString ( const char *  sql,
const unsigned char *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
const unsigned char *myValue = GetSqlResultCString("SELECT name FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
const unsigned char * Kompex::SQLiteStatement::GetSqlResultCString ( const wchar_t *  sql,
const unsigned char *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
const unsigned char *myValue = GetSqlResultCString("SELECT name FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
double Kompex::SQLiteStatement::GetSqlResultDouble ( const std::string &  sql,
double  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
double Kompex::SQLiteStatement::GetSqlResultDouble ( const char *  sql,
double  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
double Kompex::SQLiteStatement::GetSqlResultDouble ( const wchar_t *  sql,
double  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
int Kompex::SQLiteStatement::GetSqlResultInt ( const std::string &  sql,
int  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
int Kompex::SQLiteStatement::GetSqlResultInt ( const char *  sql,
int  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
int Kompex::SQLiteStatement::GetSqlResultInt ( const wchar_t *  sql,
int  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
int64 Kompex::SQLiteStatement::GetSqlResultInt64 ( const std::string &  sql,
int64  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
int64 Kompex::SQLiteStatement::GetSqlResultInt64 ( const char *  sql,
int64  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
int64 Kompex::SQLiteStatement::GetSqlResultInt64 ( const wchar_t *  sql,
int64  defaultReturnValue = -1 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
std::string Kompex::SQLiteStatement::GetSqlResultString ( const std::string &  sql,
const std::string &  defaultReturnValue = "" 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
std::string Kompex::SQLiteStatement::GetSqlResultString ( const char *  sql,
const std::string &  defaultReturnValue = "" 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
std::string Kompex::SQLiteStatement::GetSqlResultString ( const wchar_t *  sql,
const std::string &  defaultReturnValue = "" 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
wchar_t * Kompex::SQLiteStatement::GetSqlResultString16 ( const std::string &  sql,
wchar_t *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
wchar_t *myValue = GetSqlResultString16("SELECT name FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
wchar_t * Kompex::SQLiteStatement::GetSqlResultString16 ( const char *  sql,
wchar_t *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
wchar_t *myValue = GetSqlResultString16("SELECT name FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
wchar_t * Kompex::SQLiteStatement::GetSqlResultString16 ( const wchar_t *  sql,
wchar_t *  defaultReturnValue = 0 
)

Executes a SQL statement and returns instantly the result value of the first column from the first row.
Important: You must delete the returned pointer if you don't need it anymore.
e.g.
wchar_t *myValue = GetSqlResultString16("SELECT name FROM user WHERE userID = 1");
// do domething with myValue
delete[] myValue;

Parameters
sqlSQL statement
defaultReturnValueDefault return value when the SQL statement has no result
sqlite3_stmt* Kompex::SQLiteStatement::GetStatementHandle ( ) const
inlineprotected

Returns the SQLite statement handle.

void Kompex::SQLiteStatement::GetTable ( const std::string &  sql,
unsigned short  consoleOutputColumnWidth = 20 
) const

Returns the result as a complete table.
Note: only for console (textoutput)
Output: std::cout

Parameters
sqlSQL query string
consoleOutputColumnWidthWidth of the output column within the console
void Kompex::SQLiteStatement::GetTableColumnMetadata ( const std::string &  tableName,
const std::string &  columnName 
) const

Returns metadata about a specific column of a specific database table. Note: only console output
Output: std::cout

Parameters
tableNameTable in which the column is found
columnNameColumn for which we want the metadata
std::string Kompex::SQLiteStatement::Mprintf ( const char *  sql,
  ... 
)
static

Formatted String Printing Function
This function works alike the "printf()" family of functions from the standard C library.
Furthermore, it implements some additional formatting options that are useful for constructing SQL statements.
All of the usual printf() formatting options apply. In addition, there are "%q", "%Q", and "%z" options.

q option
The q option works like s in that it substitutes a null-terminated string from the argument list.
But q also doubles every '\'' character. q is designed for use inside a string literal.
By doubling each '\'' character it escapes that character and allows it to be inserted into the string.
As a general rule you should always use q instead of s when inserting text into a string literal.

Q option
The Q option works like q except it also adds single quotes around the outside of the total string.
Additionally, if the parameter in the argument list is a NULL pointer, Q substitutes the text "NULL"
(without single quotes).

z option
The "%z" formatting option works like "%s" but with the addition that after the string has been read and
copied into the result, sqlite3_free() is called on the input string.

void Kompex::SQLiteStatement::Prepare ( const char *  sqlStatement)
protected

Compile sql query into a byte-code program.

Parameters
sqlStatementSQL statement (UTF-8)
void Kompex::SQLiteStatement::Prepare ( const wchar_t *  sqlStatement)
protected

Compile sql query into a byte-code program.

Parameters
sqlStatementSQL statement (UTF-16)
void Kompex::SQLiteStatement::Reset ( ) const

Reset() is called to reset a prepared statement object back to its initial state,
ready to be re-executed. Any SQL statement variables that had values bound to them
using the Bind*() functions retain their values. Use ClearBindings() to reset the bindings.

void Kompex::SQLiteStatement::RollbackTransaction ( )
inline

Rollback a transaction.

void Kompex::SQLiteStatement::SecureTransaction ( const char *  sql)

Can be used only for transaction SQL statements.
Can be used for transactions, if you want to use the default error handling.
The SecureTransaction() method creates a internal copy of the given sql statement string,
so that you do not run into danger if the string will be invalid due to deletion or local scope.

Parameters
sqlSQL statement
void Kompex::SQLiteStatement::SecureTransaction ( const std::string  sql)

Can be used only for transaction SQL statements.
Can be used for transactions, if you want to use the default error handling.
The SecureTransaction() method creates a internal copy of the given sql statement string,
so that you do not run into danger if the string will be invalid due to deletion or local scope.

Parameters
sqlSQL statement
void Kompex::SQLiteStatement::SecureTransaction ( const wchar_t *  sql)

Can be used only for transaction SQL statements.
Can be used for transactions, if you want to use the default error handling.
The SecureTransaction() method creates a internal copy of the given sql statement string,
so that you do not run into danger if the string will be invalid due to deletion or local scope.

Parameters
sqlSQL statement
void Kompex::SQLiteStatement::Sql ( const std::string &  sql)
inline

Only for SQL queries/statements which have a result or for prepared statements.
e.g. SELECT's or INSERT's which use Bind..() methods!
Do not forget to call FreeQuery() when you have finished.

void Kompex::SQLiteStatement::Sql ( const char *  sql)
inline

Only for SQL queries/statements which have a result or for prepared statements.
e.g. SELECT's or INSERT's which use Bind..() methods!
Do not forget to call FreeQuery() when you have finished.

void Kompex::SQLiteStatement::Sql ( const std::wstring &  sql)
inline

Only for SQL queries/statements which have a result or for prepared statements.
e.g. SELECT's or INSERT's which use Bind..() methods!
Do not forget to call FreeQuery() when you have finished.

void Kompex::SQLiteStatement::Sql ( const wchar_t *  sql)
inline

Only for SQL queries/statements which have a result or for prepared statements.
e.g. SELECT's or INSERT's which use Bind..() methods!
Do not forget to call FreeQuery() when you have finished.

float Kompex::SQLiteStatement::SqlAggregateFuncResult ( const std::string &  countSql)

Can be used for all SQLite aggregate functions.
Here you can see all available aggregate functions: http://sqlite.org/lang_aggfunc.html

Parameters
countSqlComplete SQL query string (UTF-16).
float Kompex::SQLiteStatement::SqlAggregateFuncResult ( wchar_t *  countSql)

Can be used for all SQLite aggregate functions.
Here you can see all available aggregate functions: http://sqlite.org/lang_aggfunc.html

Parameters
countSqlComplete SQL query string (UTF-16).
float Kompex::SQLiteStatement::SqlAggregateFuncResult ( const char *  countSql)

Can be used for all SQLite aggregate functions.
Here you can see all available aggregate functions: http://sqlite.org/lang_aggfunc.html

Parameters
countSqlComplete SQL query string (UTF-16).
const void * Kompex::SQLiteStatement::SqlResultBlob ( const void *  defaultReturnValue)
protected

Returns the first value of the first row. Internally used in GetSqlResultBlob().

const unsigned char * Kompex::SQLiteStatement::SqlResultCString ( const unsigned char *  defaultReturnValue)
protected

Returns the first value of the first row. Internally used in GetSqlResultCString().

wchar_t * Kompex::SQLiteStatement::SqlResultString16 ( wchar_t *  defaultReturnValue)
protected

Returns the first value of the first row. Internally used in GetSqlResultString16().

void Kompex::SQLiteStatement::SqlStatement ( const std::string &  sqlStatement)
inline

Only for SQL statements which have no result (e.g. INSERT, UPDATE, etc).
Can be used for transactions; if you want, you can use an own error handling.
Please use 1 (true) and 0 (false) as bool values instead of 'true' and 'false' as string.
sqlite doesn't know these key words.

Parameters
sqlStatementSQL statement (UTF-8)
void Kompex::SQLiteStatement::SqlStatement ( const char *  sqlStatement)

Only for SQL statements which have no result (e.g. INSERT, UPDATE, etc).
Can be used for transactions; if you want, you can use an own error handling.
Please use 1 (true) and 0 (false) as bool values instead of 'true' and 'false' as string.
sqlite doesn't know these key words.

Parameters
sqlStatementSQL statement (UTF-8)
void Kompex::SQLiteStatement::SqlStatement ( const std::wstring &  sqlStatement)
inline

Only for SQL statements which have no result (e.g. INSERT, UPDATE, etc).
Can be used for transactions; if you want, you can use an own error handling.
Please use 1 (true) and 0 (false) as bool values instead of 'true' and 'false' as string.
sqlite doesn't know these key words.

Parameters
sqlStatementSQL statement (UTF-16)
void Kompex::SQLiteStatement::SqlStatement ( const wchar_t *  sqlStatement)

Only for SQL statements which have no result (e.g. INSERT, UPDATE, etc).
Can be used for transactions; if you want, you can use an own error handling.
Please use 1 (true) and 0 (false) as bool values instead of 'true' and 'false' as string.
sqlite doesn't know these key words.

Parameters
sqlStatementSQL statement (UTF-16)
bool Kompex::SQLiteStatement::Step ( ) const
protected

Must be called one or more times to evaluate the statement.

void Kompex::SQLiteStatement::Transaction ( const char *  sql)
inline

Can be used only for transaction SQL statements.
Can be used for transactions, if you want to use the default error handling. Please note that there is only used a reference of your sql statement.
If your sql statement variable is invalid before you called CommitTransaction() you need to use SecureTransaction(), which creates a internal copy of your sql statement.

Parameters
sqlSQL statement
void Kompex::SQLiteStatement::Transaction ( const std::string &  sql)
inline

Can be used only for transaction SQL statements.
Can be used for transactions, if you want to use the default error handling. Please note that there is only used a reference of your sql statement.
If your sql statement variable is invalid before you called CommitTransaction() you need to use SecureTransaction(), which creates a internal copy of your sql statement.

Parameters
sqlSQL statement
void Kompex::SQLiteStatement::Transaction ( const wchar_t *  sql)
inline

Can be used only for transaction SQL statements.
Can be used for transactions, if you want to use the default error handling. Please note that there is only used a reference of your sql statement.
If your sql statement variable is invalid before you called CommitTransaction() you need to use SecureTransaction(), which creates a internal copy of your sql statement.

Parameters
sqlSQL statement
std::string Kompex::SQLiteStatement::Vmprintf ( const char *  sql,
va_list  args 
)
static

Formatted String Printing Function
This function works alike the "printf()" family of functions from the standard C library.
Furthermore, it implements some additional formatting options that are useful for constructing SQL statements.
All of the usual printf() formatting options apply. In addition, there are "%q", "%Q", and "%z" options.

q option
The q option works like s in that it substitutes a null-terminated string from the argument list.
But q also doubles every '\'' character. q is designed for use inside a string literal.
By doubling each '\'' character it escapes that character and allows it to be inserted into the string.
As a general rule you should always use q instead of s when inserting text into a string literal.

Q option
The Q option works like q except it also adds single quotes around the outside of the total string.
Additionally, if the parameter in the argument list is a NULL pointer, Q substitutes the text "NULL"
(without single quotes).

z option
The "%z" formatting option works like "%s" but with the addition that after the string has been read and
copied into the result, sqlite3_free() is called on the input string.

Member Data Documentation

std::map<std::string , int > Kompex::SQLiteStatement::mColumnNumberToColumnNameAssignment
mutableprivate

Container which stores the assignments for every column number and the corresponding column name (cache the results).

SQLiteDatabase* Kompex::SQLiteStatement::mDatabase
private

Database pointer.

bool Kompex::SQLiteStatement::mIsColumnNumberAssignedToColumnName
mutableprivate

Saves whether the assignments for every column number and the corresponding column name was already done.

struct sqlite3_stmt* Kompex::SQLiteStatement::mStatement
private

SQL statement.

unsigned short Kompex::SQLiteStatement::mTransactionID
private

ID for transactions.

TTransactionSQL Kompex::SQLiteStatement::mTransactionSQL
private

Stores UTF-8 transaction statements.

TTransactionSQL16 Kompex::SQLiteStatement::mTransactionSQL16
private

Stores UTF-16 transaction statements.


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