Torc  0.1
torcdb.h
Go to the documentation of this file.
1 #ifndef TORCDB_H
2 #define TORCDB_H
3 
4 // Qt
5 #include <QObject>
6 #include <QMutex>
7 
8 class QSqlDatabase;
9 class QSqlQuery;
10 
11 class TorcDB
12 {
13  public:
14  TorcDB(const QString &DatabaseName, const QString &DatabaseType);
15  virtual ~TorcDB();
16 
17  bool IsValid (void);
18  void CloseThreadConnection (void);
19 
20  void LoadSettings (QMap<QString,QString> &Settings);
21  void SetSetting (const QString &Name, const QString &Value);
22 
23  protected:
24  static bool DebugError (QSqlQuery *Query);
25  static bool DebugError (QSqlDatabase *Database);
26  virtual bool InitDatabase (void) = 0;
27  QString GetThreadConnection (void);
28  void CloseConnections (void);
29 
30  protected:
32  QString m_databaseName;
33  QString m_databaseType;
34  QMutex m_lock;
35  QHash<QThread*,QString> m_connectionMap;
36 };
37 
38 #endif // TORCDB_H
TorcDB(const QString &DatabaseName, const QString &DatabaseType)
Definition: torcdb.cpp:51
bool IsValid(void)
Returns true if the datbase has been opened/created.
Definition: torcdb.cpp:70
void CloseThreadConnection(void)
Close the database connection for the current thread.
Definition: torcdb.cpp:104
QString GetThreadConnection(void)
Retrieve a database connection for the current thread.
Definition: torcdb.cpp:125
Base Sql database access class.
Definition: torcdb.h:11
QMutex m_lock
Definition: torcdb.h:34
QString m_databaseType
Definition: torcdb.h:33
QHash< QThread *, QString > m_connectionMap
Definition: torcdb.h:35
bool m_databaseValid
Definition: torcdb.h:31
virtual bool InitDatabase(void)=0
QString m_databaseName
Definition: torcdb.h:32
virtual ~TorcDB()
Definition: torcdb.cpp:60
void CloseConnections(void)
Close all cached database connections.
Definition: torcdb.cpp:79
void SetSetting(const QString &Name, const QString &Value)
Set the setting Name to the value Value.
Definition: torcdb.cpp:250
void LoadSettings(QMap< QString, QString > &Settings)
Retrieve all persistent settings stored in the database.
Definition: torcdb.cpp:229
static bool DebugError(QSqlQuery *Query)
Log database errors following a failed query.
Definition: torcdb.cpp:162