Herunterladen als
root/src/database.h @ 9e2d71d6
81c23b56 | Christian Ehringfeld | /*
|
|
6899f814 | Christian Ehringfeld | * Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
|
*
|
|||
* This program 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.
|
|||
*
|
|||
* This program 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 General Public License
|
|||
* for more details.
|
|||
*
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
|||
81c23b56 | Christian Ehringfeld | ||
#ifndef DATABASE_H
|
|||
#define DATABASE_H
|
|||
#include <QtSql/QSqlDatabase>
|
|||
#include <QtSql/QSqlDriver>
|
|||
#include <QtSql/QSqlQuery>
|
|||
#include <QDebug>
|
|||
#include <QtSql/QSqlError>
|
|||
#include <QStringList>
|
|||
#include <QList>
|
|||
#include <QString>
|
|||
#include <QDebug>
|
|||
#include "enums/databasetype.h"
|
|||
45135a14 | Christian Ehringfeld | #include "logger.h"
|
|
6899f814 | Christian Ehringfeld | namespace CuteEntityManager {
|
|
f12670e9 | Christian Ehringfeld | #ifdef QT_DEBUG
|
|
#define DEFAULTMSGTYPE MsgType::DEBUG
|
|||
#else
|
|||
#define DEFAULTMSGTYPE MsgType::CRITICAL
|
|||
#endif
|
|||
426974c6 | Christian Ehringfeld | class Database {
|
|
private:
|
|||
81c23b56 | Christian Ehringfeld | QSqlDatabase database;
|
|
QString connectionName;
|
|||
bool supportTransactions;
|
|||
45135a14 | Christian Ehringfeld | Logger *logger = nullptr;
|
|
81c23b56 | Christian Ehringfeld | void init();
|
|
3938a37e | Christian Ehringfeld | void initLogger(bool logQueries, bool logErrors, MsgType type);
|
|
45135a14 | Christian Ehringfeld | bool logQueries;
|
|
bool logErrors;
|
|||
81c23b56 | Christian Ehringfeld | ||
426974c6 | Christian Ehringfeld | public:
|
|
3938a37e | Christian Ehringfeld | Database(QSqlDatabase database, bool logQueries = false, bool logErrors = true, MsgType type = DEFAULTMSGTYPE);
|
|
81c23b56 | Christian Ehringfeld | ~Database();
|
|
a82e4cea | Christian Ehringfeld | Database(QString databaseType, QString connectionName = QString(""),
|
|
QString hostname = QString(""),
|
|||
QString databasename = QString("") ,
|
|||
QString username = QString(""), QString password = QString(""),
|
|||
54538efb | Christian Ehringfeld | qint64 port = 0, bool logQueries = false,
|
|
3938a37e | Christian Ehringfeld | bool logErrors = true, QString databaseOptions = "",
|
|
MsgType type = DEFAULTMSGTYPE);
|
|||
81c23b56 | Christian Ehringfeld | QSqlDatabase getDatabase();
|
|
QString getConnectionName();
|
|||
QSqlQuery getQuery();
|
|||
QSqlQuery getQuery(const QString &prepare);
|
|||
bool transaction(const QStringList &queries);
|
|||
bool transaction(QList<QSqlQuery> &queries);
|
|||
d568923d | Christian Ehringfeld | bool exec(const QString &query);
|
|
81c23b56 | Christian Ehringfeld | bool exec(QStringList queries);
|
|
d568923d | Christian Ehringfeld | bool exec(QSqlQuery &query);
|
|
81c23b56 | Christian Ehringfeld | bool exec(QList<QSqlQuery> queries);
|
|
d568923d | Christian Ehringfeld | void debugQuery(const QSqlQuery &query) const;
|
|
81c23b56 | Christian Ehringfeld | bool select(QSqlQuery &query);
|
|
QSqlQuery select(const QString &query);
|
|||
11bbe9a6 | Christian Ehringfeld | void startTransaction();
|
|
bool commitTransaction();
|
|||
3938a37e | Christian Ehringfeld | void logMsg(const QString &value);
|
|
95b60eb2 | Christian Ehringfeld | bool rollbackTransaction();
|
|
3820ae33 | Christian Ehringfeld | static DatabaseType getDatabaseType(QString s);
|
|
35cf13b7 | Christian Ehringfeld | static QSharedPointer<Schema> getSchema(DatabaseType db,
|
|
47f9301a | Christian Ehringfeld | QSharedPointer<Database> database);
|
|
3938a37e | Christian Ehringfeld | Logger *getLogger() const;
|
|
81c23b56 | Christian Ehringfeld | };
|
|
}
|
|||
#endif // DATABASE_H
|