#include <sqlitewrapper.h>
Public Types | |
enum | WrapperCode { WrapperOk, WrapperError } |
typedef std::map< std::string, std::string > | Row |
typedef std::vector< Row > | Result |
Public Member Functions | |
SqliteWrapper (std::string Path) | |
virtual | ~SqliteWrapper () |
WrapperCode | SqlExec (const std::string &sql_com) |
WrapperCode | ExecStatement (sqlite3_stmt *stmt) |
Result | GetTabledata () |
void | FreeResult () |
Protected Member Functions | |
WrapperCode | Check (short ret_value) |
Protected Attributes | |
std::string | dbs_path |
sqlite3 * | db_handle |
Dedupe::Dataholding::SqliteWrapper::Result | ReturningTable |
Sqlitewrapper is a wrapper to use the SQLite Database System To construct the object give a path, where the database should be written. Make sure, to have writing rights there!
Definition at line 29 of file sqlitewrapper.h.
typedef std::vector<Row> Dedupe::Dataholding::SqliteWrapper::Result |
Result holds all Rows which are given back from the last SQL-Command
Definition at line 53 of file sqlitewrapper.h.
typedef std::map<std::string,std::string> Dedupe::Dataholding::SqliteWrapper::Row |
Row holds the tablefieldname and the value as string
Definition at line 48 of file sqlitewrapper.h.
Public used datatypes for the SQL Result WrapperCode contains the returning messages from the SqliteWrapper class
Definition at line 39 of file sqlitewrapper.h.
{ WrapperOk, WrapperError };
Dedupe::Dataholding::SqliteWrapper::SqliteWrapper | ( | std::string | Path | ) |
Give the constructor the path, where the database should be written on the harddisk. The constructor did not check writting rights! This open a database where the data is readed and written. If such a database didn't exists, it will be created
Definition at line 10 of file sqlitewrapper.cpp.
: dbs_path( Path ),
db_handle( NULL ),
ReturningTable( )
{
//Open Database throw an error, if it fails
Check( sqlite3_open( dbs_path.c_str(), &db_handle ) );
}
Dedupe::Dataholding::SqliteWrapper::~SqliteWrapper | ( | ) | [virtual] |
The destructor closes the database connection and free the used memory. After calling the destructor, the data in the Result will be deleted.
Definition at line 18 of file sqlitewrapper.cpp.
References FreeResult().
{ //Free Memory FreeResult(); //Close Databaseconnection sqlite3_close( db_handle ); }
void Dedupe::Dataholding::SqliteWrapper::FreeResult | ( | ) |
This function deletes the Data from the last SELECT command.
Definition at line 130 of file sqlitewrapper.cpp.
Referenced by SqlExec(), and ~SqliteWrapper().
{ ReturningTable.clear(); }
Dedupe::Dataholding::SqliteWrapper::Result Dedupe::Dataholding::SqliteWrapper::GetTabledata | ( | ) |
Use this function to get the holded Data, if a SQL Command returns a result. The Result is READONLY
Definition at line 125 of file sqlitewrapper.cpp.
{
return Dedupe::Dataholding::SqliteWrapper::ReturningTable;
}
Dedupe::Dataholding::SqliteWrapper::WrapperCode Dedupe::Dataholding::SqliteWrapper::SqlExec | ( | const std::string & | sql_com | ) |
This function can execute every SQL command, but the result can only handle tables. It's also possible to execute more as one SQL-Command. The commands must be seperated by ";". If you call two commands, which give a result back, both results are stored. Please note, that the result will be overwritten if you call the functions a second time.
Reimplemented in Dedupe::Dataholding::Dataholding.
Definition at line 40 of file sqlitewrapper.cpp.
References FreeResult().
{ //Free the last result, if some data is stored in ReturningResult FreeResult(); sqlite3_stmt* stmt; const char* PointerToCommand = SqlCommand.c_str(); int size = SqlCommand.size(); const char* NextSqlCommand = NULL; Dedupe::Dataholding::SqliteWrapper::Row CurrentRow; //runs until no more commands existing while( PointerToCommand != NULL ) { Dedupe::Dataholding::SqliteWrapper::Check( sqlite3_prepare_v2( db_handle, PointerToCommand, size, &stmt, &NextSqlCommand ) ); //find out if one more command is waiting if( strlen( NextSqlCommand ) != 0 ) PointerToCommand = NextSqlCommand; else PointerToCommand = NULL; //get how many columns are in the table int cols = sqlite3_column_count( stmt ); //step until all results are readed out std::string name, value; while ( sqlite3_step( stmt ) == SQLITE_ROW ) { for( int i = 0; i < cols; i++ ) { if( !sqlite3_column_name( stmt, i ) ) continue; name = sqlite3_column_name( stmt, i ); if( name.empty() ) continue; if( sqlite3_column_text( stmt, i ) ) value = reinterpret_cast<const char*>( sqlite3_column_text( stmt, i )); CurrentRow[ name ] = value; } ReturningTable.push_back( CurrentRow ); } //Delete compiled SQL Statement sqlite3_finalize(stmt); } return WrapperOk; }