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

#include <database.h>

Detailed Description

Wraps an entire database into a C++ object.

Inherits Core::RefCounted.

Inherited by Db::Sqlite3Database.

Public Types

enum  AccessMode { ReadOnly , ReadWriteExisting , ReadWriteCreate }
 access modes More...
 

Public Member Functions

 Database ()
 constructor
 
virtual ~Database ()
 destructor
 
void SetURI (const IO::URI &uri)
 set the data source URI (usually filename of database file)
 
const IO::URIGetURI () const
 get the database URI
 
void SetAccessMode (AccessMode m)
 set the access mode (ReadOnly or ReadWrite)
 
AccessMode GetAccessMode () const
 get access mode
 
void SetExclusiveMode (bool b)
 enable/disable exclusive mode
 
bool GetExclusiveMode () const
 get exclusive mode
 
void SetIgnoreUnknownColumns (bool b)
 ignore unknown columns (not existing as attribute), yes/no
 
bool GetIgnoreUnknownColumns () const
 get ignore unknown columns flag
 
virtual bool Open ()
 open the database
 
virtual void Close ()
 close the database
 
bool IsOpen () const
 return true if database is open
 
const Util::StringGetError () const
 get last error string
 
virtual bool AttachDatabase (const IO::URI &uri, const Util::String &dbName)
 attach another database to the current database
 
virtual void DetachDatabase (const Util::String &dbName)
 detach an attached database
 
virtual void BeginTransaction ()
 begin a transaction on the database
 
virtual void EndTransaction ()
 end a transaction on the database
 
virtual void AddTable (const Ptr< Table > &table)
 create a new table in the database
 
virtual void DeleteTable (const Util::String &tableName)
 delete a table from the database
 
bool HasTable (const Util::String &tableName) const
 return true if a table exists by name
 
SizeT GetNumTables () const
 get number of tables in the database
 
const Ptr< Table > & GetTableByIndex (IndexT i) const
 get table by index
 
const Ptr< Table > & GetTableByName (const Util::String &tableName) const
 get table by name
 
void SetInMemoryDatabase (bool b)
 set in-memory database only
 
virtual void CopyInMemoryDatabaseToFile (const IO::URI &fileUri)
 copy in memory database to file
 
- 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

void SetError (const Util::String &error)
 set error string
 
IndexT FindTableIndex (const Util::String &tableName) const
 find a table index by name
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Protected Attributes

bool isOpen
 
bool ignoreUnknownColumns
 
IO::URI uri
 
Util::String error
 
AccessMode accessMode
 
bool memoryDatabase
 
bool exclusiveMode
 
Util::Array< Ptr< Table > > tables
 

Private Member Functions

 __DeclareClass (Database)
 

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

◆ AccessMode

access modes

Enumerator
ReadOnly 
ReadWriteExisting 
ReadWriteCreate 

Constructor & Destructor Documentation

◆ Database()

Db::Database::Database ( )

constructor

◆ ~Database()

Db::Database::~Database ( )
virtual

destructor

Member Function Documentation

◆ __DeclareClass()

Db::Database::__DeclareClass ( Database )
private

◆ AddTable()

void Db::Database::AddTable ( const Ptr< Table > & table)
virtual

create a new table in the database

Add a table to the database.

No table of the same name may exist yet in the database, otherwise an error will be thrown. If the table has values, the new database table will be initialized with those values. The table object will be connected to the database, which means any later changes to the table may be written to the database by calling the CommitChanges() method on the table.

◆ AttachDatabase()

bool Db::Database::AttachDatabase ( const IO::URI & uri,
const Util::String & dbName )
virtual

attach another database to the current database

Attach another database to this database.

Override this method in a subclass!

Reimplemented in Db::Sqlite3Database.

◆ BeginTransaction()

void Db::Database::BeginTransaction ( )
virtual

begin a transaction on the database

Begin a transaction on the database.

Override this method in a subclass.

Reimplemented in Db::Sqlite3Database.

◆ Close()

void Db::Database::Close ( )
virtual

close the database

Close the database.

A subclass should flush all pending changes and disconnect from the database.

Reimplemented in Db::Sqlite3Database.

◆ CopyInMemoryDatabaseToFile()

void Db::Database::CopyInMemoryDatabaseToFile ( const IO::URI & fileUri)
virtual

copy in memory database to file

Copy database to file.

Override this method in a subclass!

Reimplemented in Db::Sqlite3Database.

◆ DeleteTable()

void Db::Database::DeleteTable ( const Util::String & tableName)
virtual

delete a table from the database

Remove a data table from the database.

A subclass must drop the table from the database when this method is called.

◆ DetachDatabase()

void Db::Database::DetachDatabase ( const Util::String & dbName)
virtual

detach an attached database

Detach an attached database from this database.

Override this method in a subclass!

Reimplemented in Db::Sqlite3Database.

◆ EndTransaction()

void Db::Database::EndTransaction ( )
virtual

end a transaction on the database

Finish a transaction on the database.

Override this method in a subclass.

Reimplemented in Db::Sqlite3Database.

◆ FindTableIndex()

IndexT Db::Database::FindTableIndex ( const Util::String & tableName) const
protected

find a table index by name

NOTE: we cannot use a more efficient container for the tables because the table name can change anytime outside our control.

◆ GetAccessMode()

Database::AccessMode Db::Database::GetAccessMode ( ) const
inline

get access mode

◆ GetError()

const Util::String & Db::Database::GetError ( ) const
inline

get last error string

◆ GetExclusiveMode()

bool Db::Database::GetExclusiveMode ( ) const
inline

get exclusive mode

◆ GetIgnoreUnknownColumns()

bool Db::Database::GetIgnoreUnknownColumns ( ) const
inline

get ignore unknown columns flag

◆ GetNumTables()

SizeT Db::Database::GetNumTables ( ) const

get number of tables in the database

NOTE: we cannot use a more efficient container for the tables because the table name can change anytime outside our control.

◆ GetTableByIndex()

const Ptr< Table > & Db::Database::GetTableByIndex ( IndexT i) const

get table by index

NOTE: we cannot use a more efficient container for the tables because the table name can change anytime outside our control.

◆ GetTableByName()

const Ptr< Table > & Db::Database::GetTableByName ( const Util::String & tableName) const

get table by name

NOTE: we cannot use a more efficient container for the tables because the table name can change anytime outside our control.

◆ GetURI()

const IO::URI & Db::Database::GetURI ( ) const
inline

get the database URI

◆ HasTable()

bool Db::Database::HasTable ( const Util::String & tableName) const

return true if a table exists by name

NOTE: we cannot use a more efficient container for the tables because the table name can change anytime outside our control.

◆ IsOpen()

bool Db::Database::IsOpen ( ) const
inline

return true if database is open

◆ Open()

bool Db::Database::Open ( )
virtual

open the database

Open the database.

A subclass should connect to the database here and create a DataTable object for each table in the database.

Reimplemented in Db::Sqlite3Database.

◆ SetAccessMode()

void Db::Database::SetAccessMode ( AccessMode m)
inline

set the access mode (ReadOnly or ReadWrite)

◆ SetError()

void Db::Database::SetError ( const Util::String & error)
inlineprotected

set error string

◆ SetExclusiveMode()

void Db::Database::SetExclusiveMode ( bool b)
inline

enable/disable exclusive mode

◆ SetIgnoreUnknownColumns()

void Db::Database::SetIgnoreUnknownColumns ( bool b)
inline

ignore unknown columns (not existing as attribute), yes/no

◆ SetInMemoryDatabase()

void Db::Database::SetInMemoryDatabase ( bool b)
inline

set in-memory database only

◆ SetURI()

void Db::Database::SetURI ( const IO::URI & uri)
inline

set the data source URI (usually filename of database file)

Member Data Documentation

◆ accessMode

AccessMode Db::Database::accessMode
protected

◆ error

Util::String Db::Database::error
protected

◆ exclusiveMode

bool Db::Database::exclusiveMode
protected

◆ ignoreUnknownColumns

bool Db::Database::ignoreUnknownColumns
protected

◆ isOpen

bool Db::Database::isOpen
protected

◆ memoryDatabase

bool Db::Database::memoryDatabase
protected

◆ tables

Util::Array<Ptr<Table> > Db::Database::tables
protected

◆ uri

IO::URI Db::Database::uri
protected

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