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

#include <table.h>

Detailed Description

Describes a table in a database, or more abstract, a set of typed columns grouped under a common name.

Note that a table object is only a descriptor of the table layout, it never contains any actual data. If the table is attached to a database, any changes to the Table object will also lead to changes in the database (changes are batched until a CommitChanges() is invoked).

Inherits Core::RefCounted.

Inherited by Db::Sqlite3Table.

Public Types

enum  ConnectMode { ForceCreate , AssumeExists , Default }
 connection modes More...
 

Public Member Functions

 Table ()
 constructor
 
virtual ~Table ()
 destructor
 
virtual void SetName (const Util::String &n)
 set name of table
 
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 void CreateMultiColumnIndex (const Util::Array< Attr::AttrId > &columnIds)
 create a complex multicolumn index on a connected table
 
virtual Ptr< DatasetCreateDataset ()
 create a dataset associated with this table
 
virtual void CommitChanges (bool resetModifiedState=true, bool useTransaction=true)
 commit any changes (add columns, insert new rows, update modified rows)
 
bool HasUncommittedColumns () const
 check if there are any uncommitted columns in the table
 
virtual void CommitUncommittedColumns ()
 commit uncommitted columns only
 
virtual void CommitDeletedRows ()
 commit deleted rows only
 
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
 

Protected Member Functions

virtual void Connect (const Ptr< Database > &db, ConnectMode connectMode=Default, bool ignoreUnknownColumns=false)
 connect the table object with a database
 
virtual void Disconnect (bool dropTable=false)
 disconnect the table from a database, optionally remove table from database as well
 
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
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Protected Attributes

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
 

Private Member Functions

 __DeclareClass (Table)
 

Friends

class Database
 
class Dataset
 
class Writer
 

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

Member Enumeration Documentation

◆ ConnectMode

connection modes

Enumerator
ForceCreate 
AssumeExists 

‍create new table, even if table exists

Default 

‍assume the table exists

Constructor & Destructor Documentation

◆ Table()

Db::Table::Table ( )

constructor

◆ ~Table()

Db::Table::~Table ( )
virtual

destructor

Member Function Documentation

◆ __DeclareClass()

Db::Table::__DeclareClass ( Table )
private

◆ AddColumn()

void Db::Table::AddColumn ( const Column & col)

add a column to the table

Add a new column to the table.

The change will not be synchronised with the database until a CommitChanges() is called on the Table object.

◆ BindValueTable()

void Db::Table::BindValueTable ( const Ptr< ValueTable > & valTable)
protectedvirtual

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

Bind a value table to the table object.

A value table represents actual values in the table, adding, removing or modifying rows on a value table will be reflected automatically in the database. Only one value table may be bound at any time!

Reimplemented in Db::Sqlite3Table.

◆ CommitChanges()

void Db::Table::CommitChanges ( bool resetModifiedState = true,
bool useTransaction = true )
virtual

commit any changes (add columns, insert new rows, update modified rows)

Commit any changes to the database:

  • rows added to the Table object will be added in the database
  • rows deleted from the Table object will be dropped from the database All this must be implemented in a subclass.

Reimplemented in Db::Sqlite3Table.

◆ CommitDeletedRows()

void Db::Table::CommitDeletedRows ( )
virtual

commit deleted rows only

Immediately delete rows of the connected dataset from the database.

Reimplemented in Db::Sqlite3Table.

◆ CommitUncommittedColumns()

void Db::Table::CommitUncommittedColumns ( )
virtual

commit uncommitted columns only

Commit uncommitted columns to the database, this does not write any data to the database, just change the table layout.

Reimplemented in Db::Sqlite3Table.

◆ Connect()

void Db::Table::Connect ( const Ptr< Database > & db,
ConnectMode connectMode = Default,
bool ignoreUnknownColumns = false )
protectedvirtual

connect the table object with a database

Connect the table with a database:

  • if the table doesn't exist yet, it will be created, and all table object columns will be marked as uncommitted
  • if the table exists its layout will be read and added as columns to the table object unless a column exists, in this case the column will be marked as uncommitted, existing columns will be marked as committed. All this must happen in a subclass of course.

Reimplemented in Db::Sqlite3Table.

◆ CreateDataset()

Ptr< Dataset > Db::Table::CreateDataset ( )
virtual

create a dataset associated with this table

Create a dataset associated with this table.

◆ CreateMultiColumnIndex()

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

create a complex multicolumn index on a connected table

This method should be used to create multicolumn indices on the table.

The table must be connected for this method to work!

Reimplemented in Db::Sqlite3Table.

◆ Disconnect()

void Db::Table::Disconnect ( bool dropTable = false)
protectedvirtual

disconnect the table from a database, optionally remove table from database as well

Disconnect the table with a database.

If the dropTable argument is true (default is false), the actual database table will be deleted from the database as well. If dropTable is false, a CommitChanges() should be called before the table object is disconnected (this is left to the subclass).

Reimplemented in Db::Sqlite3Table.

◆ GetColumn() [1/4]

const Column & Db::Table::GetColumn ( const Attr::AttrId & id) const
inline

get a column by attribute id

◆ GetColumn() [2/4]

const Column & Db::Table::GetColumn ( const Util::FourCC & fcc) const
inline

get a column by fourCC

◆ GetColumn() [3/4]

const Column & Db::Table::GetColumn ( const Util::String & name) const
inline

get a column by name

◆ GetColumn() [4/4]

const Column & Db::Table::GetColumn ( IndexT i) const
inline

get column at index

◆ GetColumns()

const Util::Array< Column > & Db::Table::GetColumns ( ) const
inline

get all columns in the table

◆ GetDatabase()

const Ptr< Database > & Db::Table::GetDatabase ( ) const
inline

get pointer to database this table is connected to

◆ GetName()

const Util::String & Db::Table::GetName ( ) const
inline

get name of table

◆ GetNumColumns()

SizeT Db::Table::GetNumColumns ( ) const
inline

get number of columns in table

◆ GetPrimaryColumn()

const Column & Db::Table::GetPrimaryColumn ( ) const
inline

get the primary key column, fails hard if none exists

◆ HasColumn() [1/3]

bool Db::Table::HasColumn ( const Attr::AttrId & id) const
inline

return true if a column exists by attribute id

◆ HasColumn() [2/3]

bool Db::Table::HasColumn ( const Util::FourCC & fcc) const
inline

return true if a column exists by fourCC

◆ HasColumn() [3/3]

bool Db::Table::HasColumn ( const Util::String & name) const
inline

return true if a column exists by name

◆ HasPrimaryColumn()

bool Db::Table::HasPrimaryColumn ( ) const
inline

return true if a primary key column exists

◆ HasUncommittedColumns()

bool Db::Table::HasUncommittedColumns ( ) const

check if there are any uncommitted columns in the table

This method returns true if any uncommited columns exist.

These are columns that have been added with AddColumn() but have not yet been committed to the database.

◆ IsConnected()

bool Db::Table::IsConnected ( ) const
inline

return true if the table is connected to a database

◆ SetName()

void Db::Table::SetName ( const Util::String & n)
virtual

set name of table

Sets a new name for the table.

If the Table is attached to a database the change will happen immediately (this must be implemented in a subclass).

Reimplemented in Db::Sqlite3Table.

◆ UnbindValueTable()

void Db::Table::UnbindValueTable ( )
protectedvirtual

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

Unbind the currently bound value table.

This will commit any changes to the value table into the database.

Reimplemented in Db::Sqlite3Table.

Friends And Related Symbol Documentation

◆ Database

friend class Database
friend

◆ Dataset

friend class Dataset
friend

◆ Writer

friend class Writer
friend

Member Data Documentation

◆ attrIdIndexMap

Util::Dictionary<Attr::AttrId,IndexT> Db::Table::attrIdIndexMap
protected

◆ columns

Util::Array<Column> Db::Table::columns
protected

◆ database

Ptr<Database> Db::Table::database
protected

◆ fourccIndexMap

Util::Dictionary<Util::FourCC,IndexT> Db::Table::fourccIndexMap
protected

◆ isConnected

bool Db::Table::isConnected
protected

◆ name

Util::String Db::Table::name
protected

◆ nameIndexMap

Util::HashTable<Util::String,IndexT> Db::Table::nameIndexMap
protected

◆ primaryColumnIndex

IndexT Db::Table::primaryColumnIndex
protected

◆ valueTable

Ptr<ValueTable> Db::Table::valueTable
protected

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