Heart/ClientProtocol/sqldbwriter.h

110 lines
2.1 KiB
C
Raw Normal View History

2019-10-22 17:59:56 +03:00
#ifndef SQLDBWRITER_H
#define SQLDBWRITER_H
#include <QObject>
#include <QSqlDatabase>
#include <QDir>
2019-10-22 21:51:21 +03:00
#include <QSqlQuery>
2019-10-22 17:59:56 +03:00
#include "clientprotocol_global.h"
2019-10-22 21:51:21 +03:00
#include "config.h"
2019-10-25 18:18:28 +03:00
#include <QVariant>
2019-10-22 17:59:56 +03:00
class QSqlQuery;
class QSqlDatabase;
class QSqlQuery;
class PlayerDBData;
2019-10-22 21:51:21 +03:00
namespace ClientProtocol {
2019-10-25 18:18:28 +03:00
class IDbTable;
2019-10-22 21:51:21 +03:00
/**
* @brief The SqlDBWriter class
*/
2019-10-22 17:59:56 +03:00
class CLIENTPROTOCOLSHARED_EXPORT SqlDBWriter
{
private:
bool exec(QSqlQuery *sq, const QString &sqlFile);
bool initSuccessful = false;
protected:
2019-10-25 18:18:28 +03:00
/**
* @brief getDbStruct
* @return structure of the data base
*/
QHash<QString, IDbTable*> getDbStruct() const;
2019-10-22 21:51:21 +03:00
/**
* @brief enableFK - enavle forign ke for sqlite db
* @return return true if all good
*/
bool enableFK();
/**
* @brief enableFK - disavle forign ke for sqlite db
* @return return true if all good
*/
bool disableFK();
/**
* @brief getInitPararm
* @param initFile
* @return
*
* Params :
* DBDriver - driver of db see https://doc.qt.io/qt-5/sql-driver.html
* DBFilePath - path to file of data base (sqlite only)
* DBInitFile - sql file with init state database
* DBPass - pass of remote db
* DBLogin - login of remote db
* DBHost - host addres of reote db
* DBPort - port of reote db
*/
virtual QVariantMap getInitParams(const QString& initFile) const;
/**
* @brief defaultInitPararm
* @param initFile
* @return
*/
virtual QVariantMap defaultInitPararm() const;
2019-10-25 18:18:28 +03:00
/**
* @brief getType
* @param str
* @return
*/
virtual QVariant::Type getType(const QString& str);
2019-10-22 21:51:21 +03:00
QSqlQuery query;
QSqlDatabase db;
2019-10-25 18:18:28 +03:00
QHash<QString, IDbTable *> _dbStruct;
2019-10-22 17:59:56 +03:00
public:
SqlDBWriter();
2019-10-22 21:51:21 +03:00
/**
* @brief initDb
* @param path
* @return
*/
virtual bool initDb(const QString &initDbParams = DEFAULT_DB_PATH);
/**
* @brief isValid
* @return
*/
2019-10-22 17:59:56 +03:00
virtual bool isValid() const;
virtual ~SqlDBWriter();
};
2019-10-22 21:51:21 +03:00
}
2019-10-22 17:59:56 +03:00
#endif // SQLDBWRITER_H