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

#include <sqlite3table.h>

Detailed Description

Inherits Db::Table.

Public Member Functions

 Sqlite3Table ()
 constructor
 
virtual ~Sqlite3Table ()
 destructor
 
virtual void Connect (const Ptr< Database > &db, ConnectMode connectMode, bool ignoreUnknownColumn)
 connect the table object with a database
 
virtual void Disconnect (bool dropTable)
 disconnect the table from a database
 
virtual void CreateMultiColumnIndex (const Util::Array< Attr::AttrId > &columnIds)
 This method creates a multicolumn index on the table.
 
virtual void BindValueTable (const Ptr< ValueTable > &valueTable)
 bind a value table to the table object, unbinds previous table
 
virtual void UnbindValueTable ()
 unbind current value table from the table object, commits any changes to the database
 
virtual void SetName (const Util::String &n)
 set name of table
 
virtual void CommitChanges (bool resetModifiedState, bool useTransaction)
 commit any changes
 
virtual void CommitUncommittedColumns ()
 commit uncommitted columns only
 
virtual void CommitDeletedRows ()
 commit deleted rows only
 
- Public Member Functions inherited from Db::Table
 Table ()
 constructor
 
virtual ~Table ()
 destructor
 
const Util::StringGetName () const
 get name of table
 
bool IsConnected () const
 return true if the table is connected to a database
 
const Ptr< Database > & GetDatabase () const
 get pointer to database this table is connected to
 
virtual Ptr< DatasetCreateDataset ()
 create a dataset associated with this table
 
bool HasUncommittedColumns () const
 check if there are any uncommitted columns in the table
 
void AddColumn (const Column &c)
 add a column to the table
 
SizeT GetNumColumns () const
 get number of columns in table
 
const ColumnGetColumn (IndexT i) const
 get column at index
 
bool HasColumn (const Attr::AttrId &id) const
 return true if a column exists by attribute id
 
bool HasColumn (const Util::String &name) const
 return true if a column exists by name
 
bool HasColumn (const Util::FourCC &fcc) const
 return true if a column exists by fourCC
 
const ColumnGetColumn (const Attr::AttrId &id) const
 get a column by attribute id
 
const ColumnGetColumn (const Util::String &name) const
 get a column by name
 
const ColumnGetColumn (const Util::FourCC &fcc) const
 get a column by fourCC
 
const Util::Array< Column > & GetColumns () const
 get all columns in the table
 
bool HasPrimaryColumn () const
 return true if a primary key column exists
 
const ColumnGetPrimaryColumn () const
 get the primary key column, fails hard if none exists
 
- 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 (Sqlite3Table)
 
bool TableExists ()
 return true if database table exist
 
void DropTable ()
 drop database table
 
void CreateTable ()
 create database table
 
void ReadTableLayout (bool ignoreUnknownColumns)
 read the database table columns
 
Util::String BuildColumnDef (const Column &column)
 build a column definition SQL fragment
 
void CompileInsertCommand ()
 (re)compile the INSERT SQL command
 
void CompileUpdateCommand ()
 (re)compile the UPDATE SQL command
 
void CompileDeleteCommand ()
 (re)compile the DELETE SQL command
 
void ExecuteInsertCommand ()
 execute the pre-compiled INSERT command for each new row
 
void ExecuteUpdateCommand ()
 execute the pre-compiled UPDATE command for each modified row
 
void ExecuteDeleteCommand ()
 execute the pre-compiled DELETE command for each deleted row
 
void BindValueToCommand (const Ptr< Command > &cmd, IndexT wildcardIndex, IndexT valueTableColIndex, IndexT valueTableRowIndex)
 bind a value from the value table to a wildcard of a compiled command
 

Private Attributes

Ptr< CommandinsertCommand
 
Ptr< CommandupdateCommand
 
Ptr< CommanddeleteCommand
 

Static Private Attributes

static const Util::String InsertIntoFrag
 
static const Util::String OpenBracketFrag
 
static const Util::String CommaFrag
 
static const Util::String ValuesFrag
 
static const Util::String WildcardFrag
 
static const Util::String CloseBracketFrag
 
static const Util::String UpdateFrag
 
static const Util::String SetFrag
 
static const Util::String AssignWildcardFrag
 
static const Util::String TickFrag
 
static const Util::String IntegerFrag
 
static const Util::String RealFrag
 
static const Util::String TextFrag
 
static const Util::String BlobFrag
 
static const Util::String WhereFrag
 
static const Util::String DeleteFromFrag
 

Friends

class Sqlite3Database
 

Additional Inherited Members

- Public Types inherited from Db::Table
enum  ConnectMode { ForceCreate , AssumeExists , Default }
 connection modes More...
 
- 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::Table
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 
- Protected Attributes inherited from Db::Table
bool isConnected
 
Ptr< Databasedatabase
 
Ptr< ValueTablevalueTable
 
Util::String name
 
Util::Array< Columncolumns
 
Util::HashTable< Util::String, IndexTnameIndexMap
 
Util::Dictionary< Util::FourCC, IndexTfourccIndexMap
 
Util::Dictionary< Attr::AttrId, IndexTattrIdIndexMap
 
IndexT primaryColumnIndex
 

Constructor & Destructor Documentation

◆ Sqlite3Table()

Db::Sqlite3Table::Sqlite3Table ( )

constructor

◆ ~Sqlite3Table()

Db::Sqlite3Table::~Sqlite3Table ( )
virtual

destructor

NOTE: destroying a Table object does not automatically commit changes! Changes will be lost if CommitChanges() isn't called manually.

This is because the Table could have been dropped from the db, in this case a CommitChanges() would add unnessecary overhead.

Member Function Documentation

◆ __DeclareClass()

Db::Sqlite3Table::__DeclareClass ( Sqlite3Table )
private

◆ BindValueTable()

void Db::Sqlite3Table::BindValueTable ( const Ptr< ValueTable > & valueTable)
virtual

bind a value table to the table object, unbinds previous table

Reimplemented from Db::Table.

◆ BindValueToCommand()

void Db::Sqlite3Table::BindValueToCommand ( const Ptr< Command > & cmd,
IndexT wildcardIndex,
IndexT valueTableColIndex,
IndexT valueTableRowIndex )
private

bind a value from the value table to a wildcard of a compiled command

Helper method which binds a value from a value table to a command.

◆ BuildColumnDef()

String Db::Sqlite3Table::BuildColumnDef ( const Column & column)
private

build a column definition SQL fragment

Helper method which builds an SQL column definition string fragment from a column object.

◆ CommitChanges()

void Db::Sqlite3Table::CommitChanges ( bool resetModifiedState,
bool useTransaction )
virtual

commit any changes

This writes any uncommited changes to the table layout back into the database.

NOTE: it is not possible to make an existing column primary, or to create an index for an existing column, this must happen when the table is actually created! This method also does not deletion of columns (SQLite doesn't support column removal, so what...).

Reimplemented from Db::Table.

◆ CommitDeletedRows()

void Db::Sqlite3Table::CommitDeletedRows ( )
virtual

commit deleted rows only

Immediately delete rows from the database.

Reimplemented from Db::Table.

◆ CommitUncommittedColumns()

void Db::Sqlite3Table::CommitUncommittedColumns ( )
virtual

commit uncommitted columns only

This checks for uncommited column, alters the database table structure accordingly.

Reimplemented from Db::Table.

◆ CompileDeleteCommand()

void Db::Sqlite3Table::CompileDeleteCommand ( )
private

(re)compile the DELETE SQL command

Recompiles the delete command which will delete any deleted value table rows from the database.

◆ CompileInsertCommand()

void Db::Sqlite3Table::CompileInsertCommand ( )
private

(re)compile the INSERT SQL command

Recompiles the insert command which will write a complete new row back into the database.

The current implementation will only update main table rows!

◆ CompileUpdateCommand()

void Db::Sqlite3Table::CompileUpdateCommand ( )
private

(re)compile the UPDATE SQL command

Recompiles the update command which will write modified rows back into the database.

◆ Connect()

void Db::Sqlite3Table::Connect ( const Ptr< Database > & db,
ConnectMode connectMode,
bool ignoreUnknownColumns )
virtual

connect the table object with a database

This connects the table object with a database, from that moment on, all changes to the table object will be synchronized with the database.

Changes will be batched until CommitChanges() is called.

The following stuff happens at Connect() depending on the ConnectMode:

  • ConnectMode=ForceCreate: a new empty table will be created in the database, if a table of the same name exists, it will be deleted first
  • ConnectMode=AssumeExists: it is assumed that the table exists, the columns in the database will be checked against any columns in the table object and the Committed flag will be set on existing columns
  • ConnectMode=Default: it is checked first if the table exists, if not it will be acted like ForceCreate, otherwise it will be acted like AssumeExists

Reimplemented from Db::Table.

◆ CreateMultiColumnIndex()

void Db::Sqlite3Table::CreateMultiColumnIndex ( const Util::Array< Attr::AttrId > & columnIds)
virtual

This method creates a multicolumn index on the table.

The table must be connected, otherwise an assertion will be thrown!

Reimplemented from Db::Table.

◆ CreateTable()

void Db::Sqlite3Table::CreateTable ( )
private

create database table

Private helper method which creates the associated database table.

◆ Disconnect()

void Db::Sqlite3Table::Disconnect ( bool dropTable)
virtual

disconnect the table from a database

This disconnects the table from the database.

If the dropTable argument is true (default is false), the actual database table will be deleted as well. Otherwise, a CommitChanges is invoked to write any local changes back into the database, and just the C++ table object is disconnected.

Reimplemented from Db::Table.

◆ DropTable()

void Db::Sqlite3Table::DropTable ( )
private

drop database table

Private helper method which deletes the associated database table.

◆ ExecuteDeleteCommand()

void Db::Sqlite3Table::ExecuteDeleteCommand ( )
private

execute the pre-compiled DELETE command for each deleted row

This execute the pre-compiled delete command for each deleted row.

◆ ExecuteInsertCommand()

void Db::Sqlite3Table::ExecuteInsertCommand ( )
private

execute the pre-compiled INSERT command for each new row

This executes the pre-compiled insert command for each new row.

Ignores deleted rows.

◆ ExecuteUpdateCommand()

void Db::Sqlite3Table::ExecuteUpdateCommand ( )
private

execute the pre-compiled UPDATE command for each modified row

This executes the pre-compiled update command for each modified row.

Ignores deleted rows.

  • 26-Jun-07 floh fixed obscure bug where modified haven't been updated

◆ ReadTableLayout()

void Db::Sqlite3Table::ReadTableLayout ( bool ignoreUnknownColumns)
private

read the database table columns

This synchronizes this table object with the database table on a column-by-column basis.

If this table has columns which don't exist in the database, they will be added to the database table (however, this actually happens any time later during CommitChanges(). If this object is missing any columns from the db, they will be created on the table object. This method cannot be used to delete any columns from the database (in fact, deleting columns is also impossible in Sqlite).

◆ SetName()

void Db::Sqlite3Table::SetName ( const Util::String & newName)
virtual

set name of table

Set the name of the table.

If the table is connected to a database this will immediately rename the database table as well.

Reimplemented from Db::Table.

◆ TableExists()

bool Db::Sqlite3Table::TableExists ( )
private

return true if database table exist

Private helper method which checks if an associated database table exists.

◆ UnbindValueTable()

void Db::Sqlite3Table::UnbindValueTable ( )
virtual

unbind current value table from the table object, commits any changes to the database

Reimplemented from Db::Table.

Friends And Related Symbol Documentation

◆ Sqlite3Database

friend class Sqlite3Database
friend

Member Data Documentation

◆ AssignWildcardFrag

const Util::String Db::Sqlite3Table::AssignWildcardFrag
staticprivate

◆ BlobFrag

const Util::String Db::Sqlite3Table::BlobFrag
staticprivate

◆ CloseBracketFrag

const Util::String Db::Sqlite3Table::CloseBracketFrag
staticprivate

◆ CommaFrag

const Util::String Db::Sqlite3Table::CommaFrag
staticprivate

◆ deleteCommand

Ptr<Command> Db::Sqlite3Table::deleteCommand
private

◆ DeleteFromFrag

const Util::String Db::Sqlite3Table::DeleteFromFrag
staticprivate

◆ insertCommand

Ptr<Command> Db::Sqlite3Table::insertCommand
private

◆ InsertIntoFrag

const Util::String Db::Sqlite3Table::InsertIntoFrag
staticprivate

◆ IntegerFrag

const Util::String Db::Sqlite3Table::IntegerFrag
staticprivate

◆ OpenBracketFrag

const Util::String Db::Sqlite3Table::OpenBracketFrag
staticprivate

◆ RealFrag

const Util::String Db::Sqlite3Table::RealFrag
staticprivate

◆ SetFrag

const Util::String Db::Sqlite3Table::SetFrag
staticprivate

◆ TextFrag

const Util::String Db::Sqlite3Table::TextFrag
staticprivate

◆ TickFrag

const Util::String Db::Sqlite3Table::TickFrag
staticprivate

◆ updateCommand

Ptr<Command> Db::Sqlite3Table::updateCommand
private

◆ UpdateFrag

const Util::String Db::Sqlite3Table::UpdateFrag
staticprivate

◆ ValuesFrag

const Util::String Db::Sqlite3Table::ValuesFrag
staticprivate

◆ WhereFrag

const Util::String Db::Sqlite3Table::WhereFrag
staticprivate

◆ WildcardFrag

const Util::String Db::Sqlite3Table::WildcardFrag
staticprivate

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