1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-17 11:26:26 +02:00

51 lines
1.1 KiB
C
Raw Normal View History

2016-12-10 22:39:53 +00:00
#ifndef DATABASE_H
#define DATABASE_H
#include <stable.h>
#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-31 20:19:03 +00:00
~Database();
2017-01-01 23:03:42 +01:00
void initialize(const QString& path);
2017-02-07 20:11:08 +00:00
void close();
bool isClosed() const;
QSqlDatabase* database() const;
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 = "");
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:
2017-02-07 20:11:08 +00:00
QSqlDatabase* db_;
2016-12-10 22:39:53 +00:00
void upgrade();
int version() const;
mutable int version_;
2016-12-18 21:44:45 +00:00
QStringList sqlStringToLines(const QString& sql);
2017-02-09 20:14:36 +00:00
void printError(const QSqlQuery& query) const;
2017-01-02 15:04:27 +01:00
int transactionCount_;
2017-01-12 17:59:19 +01:00
bool logQueries_;
2017-02-07 20:11:08 +00:00
bool isClosed_;
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