Torc
0.1
|
Base Sql database access class. More...
#include <torcdb.h>
Public Member Functions | |
TorcDB (const QString &DatabaseName, const QString &DatabaseType) | |
virtual | ~TorcDB () |
bool | IsValid (void) |
Returns true if the datbase has been opened/created. More... | |
void | CloseThreadConnection (void) |
Close the database connection for the current thread. More... | |
void | LoadSettings (QMap< QString, QString > &Settings) |
Retrieve all persistent settings stored in the database. More... | |
void | SetSetting (const QString &Name, const QString &Value) |
Set the setting Name to the value Value. More... | |
Protected Member Functions | |
virtual bool | InitDatabase (void)=0 |
QString | GetThreadConnection (void) |
Retrieve a database connection for the current thread. More... | |
void | CloseConnections (void) |
Close all cached database connections. More... | |
Static Protected Member Functions | |
static bool | DebugError (QSqlQuery *Query) |
Log database errors following a failed query. More... | |
static bool | DebugError (QSqlDatabase *Database) |
Log database errors following database creation. More... | |
Protected Attributes | |
bool | m_databaseValid |
QString | m_databaseName |
QString | m_databaseType |
QMutex | m_lock |
QHash< QThread *, QString > | m_connectionMap |
Base Sql database access class.
TorcDB is the base implementation for Sql database access. It is currently limited to setting and retrieving settings and whilst designed for generic Sql usage, the only current concrete subclass is TorcSQliteDB. Changes may (will) be required for other database types and usage.
By default, QSql database access is not thread safe and a new connection must be opened for each thread that wishes to use the database. TorcDB (and its subclasses) will ask for a connection each time the database is accessed and connections are cached on a per-thread basis. The thread name (and pointer) is used for cache tracking and thus any thread must have a name. This implicitly limits database access to a QThread or one its subclasses (e.g. TorcQThread) and hence database access will not work from QRunnable's or other miscellaneous threads - this is by design and is NOT a bug.
TorcDB::TorcDB | ( | const QString & | DatabaseName, |
const QString & | DatabaseType | ||
) |
Definition at line 51 of file torcdb.cpp.
|
virtual |
Definition at line 60 of file torcdb.cpp.
|
protected |
Close all cached database connections.
Definition at line 79 of file torcdb.cpp.
void TorcDB::CloseThreadConnection | ( | void | ) |
Close the database connection for the current thread.
Definition at line 104 of file torcdb.cpp.
|
staticprotected |
Log database errors following a failed query.
Definition at line 162 of file torcdb.cpp.
|
staticprotected |
Log database errors following database creation.
Definition at line 193 of file torcdb.cpp.
|
protected |
Retrieve a database connection for the current thread.
Database connections are cached (thus limiting connections to one per thread).
Definition at line 125 of file torcdb.cpp.
|
protectedpure virtual |
Implemented in TorcSQLiteDB.
bool TorcDB::IsValid | ( | void | ) |
Returns true if the datbase has been opened/created.
Definition at line 70 of file torcdb.cpp.
void TorcDB::LoadSettings | ( | QMap< QString, QString > & | Settings | ) |
Retrieve all persistent settings stored in the database.
Settings are key/value pairs (of strings).
Settings are designed as application wide configurable settings that can only changed by the administrative user (if present, otherwise the default user).
Definition at line 229 of file torcdb.cpp.
void TorcDB::SetSetting | ( | const QString & | Name, |
const QString & | Value | ||
) |
Set the setting Name to the value Value.
Definition at line 250 of file torcdb.cpp.