Nebula
Loading...
Searching...
No Matches
Db::Sqlite3Command Class Reference

#include <sqlite3command.h>

Detailed Description

SQLite3 implementation of Db::Command.

Inherits Db::Command.

Public Member Functions

 Sqlite3Command ()
 constructor
virtual ~Sqlite3Command ()
 destructor
virtual bool Compile (const Ptr< Database > &db, const Util::String &sqlCommand, ValueTable *resultTable=0)
 compile an SQL statement with optional placeholders
virtual bool Execute ()
 execute compiled command
virtual void Clear ()
 clear the current command
virtual bool IsValid () const
 return true if command is compiled and ready for execution
virtual IndexT IndexOf (const Util::String &name) const
 convert a parameter name into an integer index
virtual IndexT IndexOf (const Attr::AttrId &attrId) const
 convert a parameter attribute id into an integer index
virtual void BindInt (IndexT index, int val)
 bind an integer by placeholder index
virtual void BindFloat (IndexT index, float val)
 bind a float by placeholder index
virtual void BindBool (IndexT index, bool val)
 bind a bool by placeholder index
virtual void BindVec4 (IndexT index, const Math::vec4 &val)
 bind a vec4 by placeholder index
virtual void BindString (IndexT index, const Util::String &val)
 bind a string by placeholder index
virtual void BindMat4 (IndexT index, const Math::mat4 &val)
 bind a Math::mat4 by placeholder index
virtual void BindBlob (IndexT index, const Util::Blob &val)
 bind a blob by placeholder index
virtual void BindGuid (IndexT index, const Util::Guid &val)
 bind a guid by placeholder index
virtual void BindInt (const Util::String &name, int val)
 bind an integer by placeholder name
virtual void BindFloat (const Util::String &name, float val)
 bind a float by placeholder name
virtual void BindBool (const Util::String &name, bool val)
 bind a bool by placeholder name
virtual void BindVec4 (const Util::String &name, const Math::vec4 &val)
 bind a vec4 by placeholder name
virtual void BindString (const Util::String &name, const Util::String &val)
 bind a string by placeholder name
virtual void BindMat4 (const Util::String &name, const Math::mat4 &val)
 bind a Math::mat4 by placeholder name
virtual void BindBlob (const Util::String &name, const Util::Blob &val)
 bind a blob by placeholder name
virtual void BindGuid (const Util::String &name, const Util::Guid &val)
 bind a guid by placeholder name
virtual void BindInt (const Attr::AttrId &id, int val)
 bind an integer by placeholder attribute id
virtual void BindFloat (const Attr::AttrId &id, float val)
 bind a float by placeholder attribute id
virtual void BindBool (const Attr::AttrId &id, bool val)
 bind a bool by placeholder attribute id
virtual void BindVec4 (const Attr::AttrId &id, const Math::vec4 &val)
 bind a float4 by placeholder attribute id
virtual void BindString (const Attr::AttrId &id, const Util::String &val)
 bind a string by placeholder attribute id
virtual void BindMat4 (const Attr::AttrId &id, const Math::mat4 &val)
 bind a Math::mat4 by placeholder attribute id
virtual void BindBlob (const Attr::AttrId &id, const Util::Blob &val)
 bind a blob by placeholder attribute id
virtual void BindGuid (const Attr::AttrId &id, const Util::Guid &val)
 bind a guid by placeholder attribute id
Public Member Functions inherited from Db::Command
 Command ()
 constructor
virtual ~Command ()
 destructor
bool CompileAndExecute (const Ptr< Database > &db, const Util::String &sqlCommand, ValueTable *resultTable=0)
 shortcut for simple SQL commands
const Util::StringGetError () const
 get last error
const Ptr< Database > & GetDatabase () const
 get back pointer to database
const Util::StringGetSqlCommand () const
 get the last compiled SQL command
const Ptr< ValueTable > & GetValueTable () const
 get the last set value table (can be 0!)
Public Member Functions inherited from Core::RefCounted
 RefCounted ()
 constructor
int GetRefCount () const
 get the current refcount
void AddRef ()
 increment refcount by one
void Release ()
 decrement refcount and destroy object if refcount is zero
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
const Util::StringGetClassName () const
 get the class name
Util::FourCC GetClassFourCC () const
 get the class FourCC code

Private Member Functions

 __DeclareClass (Sqlite3Command)
void SetSqliteError ()
 set current error string to SQLite's error message
void ReadRow ()
 add a new row of results

Private Attributes

sqlite3_stmt * sqliteStatement
Util::Array< IndexTresultIndexMap

Additional Inherited Members

Static Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
Protected Member Functions inherited from Db::Command
void SetError (const Util::String &err)
 set error string
void SetSqlCommand (const Util::String &cmd)
 set the SQL statement to exeute
Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
Protected Attributes inherited from Db::Command
Util::String sqlCommand
Util::String error
Ptr< Databasedatabase
Ptr< ValueTablevalueTable

Constructor & Destructor Documentation

◆ Sqlite3Command()

Db::Sqlite3Command::Sqlite3Command ( )

constructor

◆ ~Sqlite3Command()

Db::Sqlite3Command::~Sqlite3Command ( )
virtual

destructor

Member Function Documentation

◆ __DeclareClass()

Db::Sqlite3Command::__DeclareClass ( Sqlite3Command )
private

◆ BindBlob() [1/3]

void Db::Sqlite3Command::BindBlob ( const Attr::AttrId & id,
const Util::Blob & val )
virtual

bind a blob by placeholder attribute id

Implements Db::Command.

◆ BindBlob() [2/3]

void Db::Sqlite3Command::BindBlob ( const Util::String & name,
const Util::Blob & val )
virtual

bind a blob by placeholder name

Implements Db::Command.

◆ BindBlob() [3/3]

void Db::Sqlite3Command::BindBlob ( IndexT index,
const Util::Blob & val )
virtual

bind a blob by placeholder index

Bind a string value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index. index.

Implements Db::Command.

◆ BindBool() [1/3]

void Db::Sqlite3Command::BindBool ( const Attr::AttrId & id,
bool val )
virtual

bind a bool by placeholder attribute id

Implements Db::Command.

◆ BindBool() [2/3]

void Db::Sqlite3Command::BindBool ( const Util::String & name,
bool val )
virtual

bind a bool by placeholder name

Implements Db::Command.

◆ BindBool() [3/3]

void Db::Sqlite3Command::BindBool ( IndexT index,
bool b )
virtual

bind a bool by placeholder index

Bind a bool value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index.

Implements Db::Command.

◆ BindFloat() [1/3]

void Db::Sqlite3Command::BindFloat ( const Attr::AttrId & id,
float val )
virtual

bind a float by placeholder attribute id

Implements Db::Command.

◆ BindFloat() [2/3]

void Db::Sqlite3Command::BindFloat ( const Util::String & name,
float val )
virtual

bind a float by placeholder name

Implements Db::Command.

◆ BindFloat() [3/3]

void Db::Sqlite3Command::BindFloat ( IndexT index,
float val )
virtual

bind a float by placeholder index

Bind a float value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index.

Implements Db::Command.

◆ BindGuid() [1/3]

void Db::Sqlite3Command::BindGuid ( const Attr::AttrId & id,
const Util::Guid & val )
virtual

bind a guid by placeholder attribute id

Implements Db::Command.

◆ BindGuid() [2/3]

void Db::Sqlite3Command::BindGuid ( const Util::String & name,
const Util::Guid & val )
virtual

bind a guid by placeholder name

Implements Db::Command.

◆ BindGuid() [3/3]

void Db::Sqlite3Command::BindGuid ( IndexT index,
const Util::Guid & val )
virtual

bind a guid by placeholder index

Bind a guid value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index. index.

Implements Db::Command.

◆ BindInt() [1/3]

void Db::Sqlite3Command::BindInt ( const Attr::AttrId & id,
int val )
virtual

bind an integer by placeholder attribute id

Implements Db::Command.

◆ BindInt() [2/3]

void Db::Sqlite3Command::BindInt ( const Util::String & name,
int val )
virtual

bind an integer by placeholder name

Implements Db::Command.

◆ BindInt() [3/3]

void Db::Sqlite3Command::BindInt ( IndexT index,
int val )
virtual

bind an integer by placeholder index

Bind an integer value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index.

Implements Db::Command.

◆ BindMat4() [1/3]

void Db::Sqlite3Command::BindMat4 ( const Attr::AttrId & id,
const Math::mat4 & val )
virtual

bind a Math::mat4 by placeholder attribute id

Implements Db::Command.

◆ BindMat4() [2/3]

void Db::Sqlite3Command::BindMat4 ( const Util::String & name,
const Math::mat4 & val )
virtual

bind a Math::mat4 by placeholder name

Implements Db::Command.

◆ BindMat4() [3/3]

void Db::Sqlite3Command::BindMat4 ( IndexT index,
const Math::mat4 & val )
virtual

bind a Math::mat4 by placeholder index

Bind a Math::mat4 value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index.

Implements Db::Command.

◆ BindString() [1/3]

void Db::Sqlite3Command::BindString ( const Attr::AttrId & id,
const Util::String & val )
virtual

bind a string by placeholder attribute id

Implements Db::Command.

◆ BindString() [2/3]

void Db::Sqlite3Command::BindString ( const Util::String & name,
const Util::String & val )
virtual

bind a string by placeholder name

Implements Db::Command.

◆ BindString() [3/3]

void Db::Sqlite3Command::BindString ( IndexT index,
const Util::String & val )
virtual

bind a string by placeholder index

Bind a string value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index.. NOTE: the string should be in UTF-8 format.

Implements Db::Command.

◆ BindVec4() [1/3]

void Db::Sqlite3Command::BindVec4 ( const Attr::AttrId & id,
const Math::vec4 & val )
virtual

bind a float4 by placeholder attribute id

Implements Db::Command.

◆ BindVec4() [2/3]

void Db::Sqlite3Command::BindVec4 ( const Util::String & name,
const Math::vec4 & val )
virtual

bind a vec4 by placeholder name

Implements Db::Command.

◆ BindVec4() [3/3]

void Db::Sqlite3Command::BindVec4 ( IndexT index,
const Math::vec4 & val )
virtual

bind a vec4 by placeholder index

Bind a float4 value by placeholder index.

Either get the index from one of the IndexOf methods or use a 0-based index.

Implements Db::Command.

◆ Clear()

void Db::Sqlite3Command::Clear ( )
virtual

clear the current command

Clears the currently compiled command.

Implements Db::Command.

◆ Compile()

bool Db::Sqlite3Command::Compile ( const Ptr< Database > & db,
const Util::String & sqlCommand,
ValueTable * resultTable = 0 )
virtual

compile an SQL statement with optional placeholders

Compiles a command with optional placeholders.

Placeholders are identified by a leading $. After the command has been compiled, actual values can be bound to the placeholders using the Bind*() methods. When everything is in place, use Execute() to execute the command. If compilation fails, the method will return false. Get an error description with the method GetError().

Remember that the SQL statement string must be UTF-8 encoded!

Reimplemented from Db::Command.

◆ Execute()

bool Db::Sqlite3Command::Execute ( )
virtual

execute compiled command

Execute a compiled command and gather the result.

Implements Db::Command.

◆ IndexOf() [1/2]

IndexT Db::Sqlite3Command::IndexOf ( const Attr::AttrId & attrId) const
virtual

convert a parameter attribute id into an integer index

Returns the index of a placeholder value by attribute id.

NOTE: this method is slow because a temporary string must be created! It's much faster to work with unnamed wildcards ("?") and set them directly by index!

Implements Db::Command.

◆ IndexOf() [2/2]

IndexT Db::Sqlite3Command::IndexOf ( const Util::String & name) const
virtual

convert a parameter name into an integer index

Returns the index of a placeholder value by name.

The placeholder name must be UTF-8 encoded! NOTE: this method is slow because a temporary string must be created! It's much faster to work with unnamed wildcards ("?") and set them directly by index!

Implements Db::Command.

◆ IsValid()

bool Db::Sqlite3Command::IsValid ( ) const
virtual

return true if command is compiled and ready for execution

Returns true if the command has been compiled and is ready for execution, false if the command needs to be recompiled.

Implements Db::Command.

◆ ReadRow()

void Db::Sqlite3Command::ReadRow ( )
private

add a new row of results

Gather row of result values from SQLite and add them to the result ValueTable.

Note that modification tracking is turned off in the value table, because reading from the database doesn't count as modification.

ptr = ByteOrder::ConvertFloat4(ByteOrder::LittleEndian, ByteOrder::Host, *ptr);

◆ SetSqliteError()

void Db::Sqlite3Command::SetSqliteError ( )
private

set current error string to SQLite's error message

Member Data Documentation

◆ resultIndexMap

Util::Array<IndexT> Db::Sqlite3Command::resultIndexMap
private

◆ sqliteStatement

sqlite3_stmt* Db::Sqlite3Command::sqliteStatement
private

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