Nut/src/database.h

99 lines
2.6 KiB
C
Raw Normal View History

2016-05-12 14:08:58 +08:00
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Nut is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
2017-02-01 18:01:21 +08:00
#ifndef NUTDATABASE_H
#define NUTDATABASE_H
2016-05-12 14:08:58 +08:00
#include <QtCore/qglobal.h>
#include <QtCore/QList>
#include <QtSql/QSqlDatabase>
2019-06-07 16:19:20 +08:00
#include <QSharedDataPointer>
2016-05-12 14:08:58 +08:00
#include "defines.h"
#include "tableset.h"
2017-02-01 18:01:21 +08:00
NUT_BEGIN_NAMESPACE
2016-05-12 14:08:58 +08:00
class DatabaseModel;
class DatabasePrivate;
class TableSetBase;
class SqlGeneratorBase;
2017-02-01 18:01:21 +08:00
class ChangeLogTable;
2016-05-12 14:08:58 +08:00
class NUT_EXPORT Database : public QObject
{
Q_OBJECT
2019-06-07 16:19:20 +08:00
// QSharedDataPointer<DatabasePrivate> *_d;
2016-05-12 14:08:58 +08:00
DatabasePrivate *d_ptr;
Q_DECLARE_PRIVATE(Database)
public:
2019-01-09 23:49:50 +08:00
explicit Database(QObject *parent = nullptr);
2018-02-26 18:14:36 +08:00
explicit Database(const Database &other);
explicit Database(const QSqlDatabase &other);
2017-05-25 23:46:54 +08:00
~Database();
2016-05-12 14:08:58 +08:00
bool open();
bool open(bool updateDatabase);
2016-06-05 20:22:26 +08:00
void close();
2016-05-12 14:08:58 +08:00
2019-02-10 22:11:22 +08:00
QSqlQuery exec(const QString& sql);
2016-05-12 14:08:58 +08:00
2017-09-10 22:18:20 +08:00
int saveChanges(bool cleanUp = false);
2016-05-21 16:09:03 +08:00
void cleanUp();
2016-05-12 14:08:58 +08:00
QString databaseName() const;
QString hostName() const;
int port() const;
QString userName() const;
QString password() const;
QString connectionName() const;
QString driver() const;
DatabaseModel model() const;
QString tableName(QString className);
SqlGeneratorBase *sqlGenertor() const;
2018-02-13 23:39:21 +08:00
QSqlDatabase database();
2016-05-12 14:08:58 +08:00
2016-06-05 20:22:26 +08:00
protected:
2017-08-10 23:09:41 +08:00
//remove minor version
2019-04-09 15:25:19 +08:00
virtual void databaseCreated();
2019-02-16 21:36:38 +08:00
virtual void databaseUpdated(int oldVersion, int newVersion);
2016-06-05 20:22:26 +08:00
2016-05-12 14:08:58 +08:00
public slots:
void setDatabaseName(QString databaseName);
void setHostName(QString hostName);
void setPort(int port);
void setUserName(QString userName);
void setPassword(QString password);
void setConnectionName(QString connectionName);
void setDriver(QString driver);
private:
2017-09-10 22:18:20 +08:00
void add(TableSetBase *);
friend class TableSetBase;
2016-05-12 14:08:58 +08:00
};
2017-02-01 18:01:21 +08:00
NUT_END_NAMESPACE
2016-05-12 14:08:58 +08:00
2017-05-25 23:46:54 +08:00
#endif // NUTDATABASE_H