FactDev  0.1
database.h
1 #ifndef Database_H
2 #define Database_H
3 
4 #include <QtSql/QSql>
5 #include <QtSql/QSqlQuery>
6 #include <QtSql/QSqlError>
7 #include <QtSql/QSqlRecord>
8 
9 #include <QStandardItemModel>
10 #include <QSettings>
11 #include <QStandardItem>
12 #include <QDate>
13 #include <QCoreApplication>
14 #include <QFile>
15 
16 #include <exception>
17 
18 #include "exceptions/dbexception.h"
19 #include "utils/log.h"
20 #include "parameters.h"
21 #include "database/accessdatabase.h"
22 
23 using namespace Exceptions;
24 using namespace Utils;
25 
29 namespace Databases {
34 class Database {
35 public:
40  static Database* instance(bool tests=false) throw(DbException*);
41 
48  QString lastError(const QSqlQuery& q) const;
49 
53  void testCases();
54 
60  void executeFile(QString pName);
61 
65  void openTransaction();
66 
70  void closeTransaction();
71 
75  void close();
76 
80  void open();
81 
85  ~Database();
86 
91  void setDatabase(QSqlDatabase sql);
92 
96  void updateBillingNumber();
97 
102  void cleanDatabase();
103 
108  void changeDatabase(Databases::DbType dbType);
109 protected:
113  Database(bool tests=false)throw(DbException*);
114 
115  static Database* _instance;
116  static bool _dbInstance;
117 
118  QSettings* _settings;
119 
120  QSqlDatabase mDatabase;
121  QList<Database*> _instances;
122 
123  static bool isOpen;
124 
131  QVariant value(const QSqlQuery& q, const QString& champ) const;
132 
133  static bool _isMysql;
134 
135 };
136 
137 }
138 #endif // Database_H
The DbException class for database exception : queries, db file, …
Definition: dbexception.h:18
The Database class Master class for all database access.
Definition: database.h:34
static bool _dbInstance
an instance of db is open
Definition: database.h:116
QSqlDatabase mDatabase
contains Database
Definition: database.h:120
static bool isOpen
Database is open.
Definition: database.h:123
QList< Database * > _instances
List of instances.
Definition: database.h:121
QSettings * _settings
settings
Definition: database.h:118
static Database * _instance
Instance.
Definition: database.h:115