Kompex::SQLiteStatement Class Reference

#include <KompexSQLiteStatement.h>

List of all members.

Public Member Functions

 SQLiteStatement (SQLiteDatabase *db)
virtual ~SQLiteStatement ()
 Destructor.
void SqlStatement (const std::string &sqlStatement)
void SqlStatement (const char *sqlStatement)
void SqlStatement (const wchar_t *sqlStatement)
void Sql (const std::string &sql)
void Sql (wchar_t *sql)
void Sql (const char *sql)
bool FetchRow () const
 If you have called Sql(), you can step throw all results.
void FreeQuery ()
 Call FreeQuery() after Sql() and FetchRow() to clean-up.
float SqlAggregateFuncResult (const std::string &countSql)
float SqlAggregateFuncResult (wchar_t *countSql)
float SqlAggregateFuncResult (const char *countSql)
const char * GetColumnName (int column) const
wchar_t * GetColumnName16 (int column) const
int GetColumnType (int column) const
const unsigned char * GetColumnCString (int column) const
std::string GetColumnString (int column) const
wchar_t * GetColumnString16 (int column) const
double GetColumnDouble (int column) const
int GetColumnInt (int column) const
int64 GetColumnInt64 (int column) const
const void * GetColumnBlob (int column) const
int GetColumnCount () const
int GetColumnBytes (int column) const
int GetColumnBytes16 (int column) const
const char * GetColumnDatabaseName (int column) const
wchar_t * GetColumnDatabaseName16 (int column) const
const char * GetColumnTableName (int column) const
wchar_t * GetColumnTableName16 (int column) const
const char * GetColumnOriginName (int column) const
wchar_t * GetColumnOriginName16 (int column) const
const char * GetColumnDeclaredDatatype (int column) const
wchar_t * GetColumnDeclaredDatatype16 (int column) const
int GetDataCount () const
void BindInt (int column, int value) const
void BindString (int column, const std::string &string) const
void BindString16 (int column, const wchar_t *string) 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 BindZeroBlob (int column, int length) 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.
void CommitTransaction ()
void RollbackTransaction ()
 Rollback a transaction.
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)

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.
void CheckStatement () const
 Checks if the statement pointer is valid.
void CheckDatabase () const
 Checks if the database pointer is valid.
void FreeAllStatements ()
 Clean-up all statements.
template<class T >
void DeleteTransactionSqlStr (bool isMemAllocated, T *str)
 Free the allocated memory of sql statements.
void CleanUpTransaction ()
 Free the allocated memory and clean the containers.

Private Types

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

Private Attributes

struct sqlite3_stmt * mStatement
 SQL statement.
SQLiteDatabasemDatabase
 Database pointer.
TTransactionSQL mTransactionSQL
 Stores UTF-8 transaction statements.
TTransactionSQL16 mTransactionSQL16
 Stores UTF-16 transaction statements.
unsigned short mTransactionID
 id for transactions

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:
db Database in which the SQL should be performed
Kompex::SQLiteStatement::~SQLiteStatement (  )  [virtual]

Destructor.


Member Function Documentation

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:
column Column, in which the data should be inserted
data BLOB data which should inserted in the indicated column
numberOfBytes The 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::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:
column Column, in which the data should be inserted
value double value which should 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:
column Column, in which the data should be inserted
value int value which should 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:
column Column, in which the data should be inserted
value int64 value which should 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:
column Column, 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:
column Column, in which the data should be inserted
string UTF-8 string which should 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:
column Column, in which the data should be inserted
string UTF-16 string which should inserted in the indicated column
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:
column Column, in which the data should be inserted
length length of BLOB, which is filled with zeroes
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 
) [inline, protected]

Free the allocated memory of sql statements.

void Kompex::SQLiteStatement::ExecuteAndFree (  ) 

Executes a INSERT 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.

void Kompex::SQLiteStatement::FreeAllStatements (  )  [protected]

Clean-up all statements.

void Kompex::SQLiteStatement::FreeQuery (  ) 

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

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()!

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()!

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()!

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.
You must first call Sql()!

const char * Kompex::SQLiteStatement::GetColumnDatabaseName ( int  column  )  const

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

wchar_t * Kompex::SQLiteStatement::GetColumnDatabaseName16 ( int  column  )  const

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

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()!

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()!

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()!

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()!

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()!

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()!

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()!

const char * Kompex::SQLiteStatement::GetColumnOriginName ( int  column  )  const

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

wchar_t * Kompex::SQLiteStatement::GetColumnOriginName16 ( int  column  )  const

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

std::string Kompex::SQLiteStatement::GetColumnString ( int  column  )  const

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

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.
You must first call Sql()!

const char * Kompex::SQLiteStatement::GetColumnTableName ( int  column  )  const

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

wchar_t * Kompex::SQLiteStatement::GetColumnTableName16 ( int  column  )  const

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

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()!

int Kompex::SQLiteStatement::GetDataCount (  )  const [inline]

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

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:
sql SQL query string
consoleOutputColumnWidth Width 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:
tableName Table in which the column is found
columnName Column for which we want the metadata
void Kompex::SQLiteStatement::Prepare ( const wchar_t *  sqlStatement  )  [protected]

Compile sql query into a byte-code program.

Parameters:
sqlStatement SQL statement (UTF-16)
void Kompex::SQLiteStatement::Prepare ( const char *  sqlStatement  )  [protected]

Compile sql query into a byte-code program.

Parameters:
sqlStatement SQL statement (UTF-8)
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 wchar_t *  sql  ) 

Can be used only for transaction SQL statements.
Can be used for transactions, if you want 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:
sql SQL 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 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:
sql SQL statement
void Kompex::SQLiteStatement::SecureTransaction ( const char *  sql  ) 

Can be used only for transaction SQL statements.
Can be used for transactions, if you want 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:
sql SQL statement
void Kompex::SQLiteStatement::Sql ( const char *  sql  )  [inline]

Only for SQL queries/statements which have a result.
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 ( wchar_t *  sql  )  [inline]

Only for SQL queries/statements which have a result.
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::string &  sql  )  [inline]

Only for SQL queries/statements which have a result.
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 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:
countSql Complete 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:
countSql Complete SQL query string (UTF-16).
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:
countSql Complete SQL query string (UTF-16).
void Kompex::SQLiteStatement::SqlStatement ( const wchar_t *  sqlStatement  ) 

Only for SQL statements, which have no result. Can be used for transactions; if you want, you can use an own error handling.

Parameters:
sqlStatement SQL statement (UTF-16)
void Kompex::SQLiteStatement::SqlStatement ( const char *  sqlStatement  ) 

Only for SQL statements, which have no result. Can be used for transactions; if you want, you can use an own error handling.

Parameters:
sqlStatement SQL statement (UTF-8)
void Kompex::SQLiteStatement::SqlStatement ( const std::string &  sqlStatement  ) 

Only for SQL statements, which have no result. Can be used for transactions; if you want, you can use an own error handling.

Parameters:
sqlStatement SQL statement (UTF-8)
bool Kompex::SQLiteStatement::Step (  )  const [protected]

Must be called one or more times to evaluate the 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 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:
sql SQL 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 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:
sql SQL 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 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:
sql SQL statement

Member Data Documentation

Database pointer.

struct sqlite3_stmt* Kompex::SQLiteStatement::mStatement [private]

SQL statement.

unsigned short Kompex::SQLiteStatement::mTransactionID [private]

id for transactions

Stores UTF-8 transaction statements.

Stores UTF-16 transaction statements.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Defines
Generated on Thu Jul 15 21:07:12 2010 for Kompex SQLite Wrapper by  doxygen 1.6.3