2016-12-10 22:39:53 +00:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
#define DATABASE_H
|
|
|
|
|
|
|
|
#include <stable.h>
|
2017-01-02 13:17:15 +01:00
|
|
|
#include "enum.h"
|
2016-12-29 21:45:38 +01:00
|
|
|
#include "simpletypes.h"
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
namespace jop {
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-12-29 21:45:38 +01:00
|
|
|
enum QueryType { Select, Insert, Update, Delete };
|
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
Database();
|
2017-01-01 23:03:42 +01:00
|
|
|
void initialize(const QString& path);
|
2016-12-29 20:19:00 +01:00
|
|
|
QSqlDatabase& database();
|
2016-12-29 21:45:38 +01:00
|
|
|
QSqlQuery buildSqlQuery(Database::QueryType type, const QString& tableName, const QStringList& fields, const VariantVector& values, const QString& whereCondition = "");
|
2017-01-02 13:17:15 +01:00
|
|
|
QSqlQuery buildSqlQuery(Database::QueryType type, const QString& tableName, const QMap<QString, QVariant>& values, const QString& whereCondition = "");
|
2017-01-01 11:33:14 +01:00
|
|
|
bool errorCheck(const QSqlQuery& query);
|
2017-01-02 15:04:27 +01:00
|
|
|
bool transaction();
|
|
|
|
bool commit();
|
2017-01-02 15:17:03 +01:00
|
|
|
bool execQuery(QSqlQuery &query);
|
2017-01-05 23:54:13 +01:00
|
|
|
bool execQuery(const QString &query);
|
2017-01-03 19:42:01 +01:00
|
|
|
QSqlQuery prepare(const QString& sql);
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QSqlDatabase db_;
|
|
|
|
void upgrade();
|
|
|
|
int version() const;
|
|
|
|
mutable int version_;
|
2016-12-18 21:44:45 +00:00
|
|
|
QStringList sqlStringToLines(const QString& sql);
|
2017-01-02 15:04:27 +01:00
|
|
|
int transactionCount_;
|
2017-01-12 17:59:19 +01:00
|
|
|
bool logQueries_;
|
2016-12-10 22:39:53 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-01-01 23:03:42 +01:00
|
|
|
|
|
|
|
Database& db();
|
|
|
|
|
2016-12-10 22:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DATABASE_H
|