Nut  0.1
database.h
1 /**************************************************************************
2 **
3 ** This file is part of Nut project.
4 ** https://github.com/HamedMasafi/Nut
5 **
6 ** Nut is free software: you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation, either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** Nut is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU Lesser General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with Nut. If not, see <http://www.gnu.org/licenses/>.
18 **
19 **************************************************************************/
20 
21 #ifndef DATABASE_H
22 #define DATABASE_H
23 
24 #include <QtCore/qglobal.h>
25 #include <QtCore/QList>
26 #include <QtSql/QSqlDatabase>
27 
28 #include "defines.h"
29 #include "tableset.h"
30 
31 QT_BEGIN_NAMESPACE
32 
33 class DatabaseModel;
34 class DatabasePrivate;
35 class TableSetBase;
36 class SqlGeneratorBase;
37 class NUT_EXPORT Database : public QObject
38 {
39  Q_OBJECT
40 
41  DatabasePrivate *d_ptr;
42  Q_DECLARE_PRIVATE(Database)
43 
44 public:
45  Database(QObject *parent = 0);
46 
47  bool open();
48  void close();
49 
50  QSqlQuery exec(QString sql);
51 
52  void add(TableSetBase *);
53  void saveChanges();
54  void cleanUp();
55 
56  QString databaseName() const;
57  QString hostName() const;
58  int port() const;
59  QString userName() const;
60  QString password() const;
61  QString connectionName() const;
62  QString driver() const;
63 
64  DatabaseModel model() const;
65  QString tableName(QString className);
66 
67  SqlGeneratorBase *sqlGenertor() const;
68 
69 protected:
70  virtual void databaseUpdated(int oldMajor, int oldMinor, int newMajor, int newMinor);
71 
72 public slots:
73  void setDatabaseName(QString databaseName);
74  void setHostName(QString hostName);
75  void setPort(int port);
76  void setUserName(QString userName);
77  void setPassword(QString password);
78  void setConnectionName(QString connectionName);
79  void setDriver(QString driver);
80 
81 private:
82  QSet<TableSetBase*> tableSets;
83 };
84 
85 QT_END_NAMESPACE
86 
87 #endif // DATABASE_H