4
1
mirror of https://github.com/QuasarApp/Heart.git synced 2025-05-02 20:49:40 +00:00

Merge pull request from QuasarApp/some_fixes

Qupdate Quasarapp lib
This commit is contained in:
Andrei Yankovich 2023-10-01 14:19:37 +03:00 committed by GitHub
commit 214b24897f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 11 deletions

@ -28,6 +28,16 @@
#define DEFAULT_DB_INIT_FILE_PATH ":/sql/res/BaseDB.sql" // default database file path #define DEFAULT_DB_INIT_FILE_PATH ":/sql/res/BaseDB.sql" // default database file path
#define DEFAULT_UPDATE_INTERVAL 3600000 // This is interval of update database cache by default it is 1 hour #define DEFAULT_UPDATE_INTERVAL 3600000 // This is interval of update database cache by default it is 1 hour
// Database settings keys
#define QH_DB_DRIVER "DBDriver"
#define QH_DB_FILE_PATH "DBFilePath"
#define QH_DB_INIT_FILE "DBInitFile"
#define QH_DB_PASS "DBPass"
#define QH_DB_LOGIN "DBLogin"
#define QH_DB_HOST "DBHost"
#define QH_DB_PORT "DBPort"
#define QH_DB_BACKUP_PATH "DBBackUpPath"
// Transport Protockol settings // Transport Protockol settings
#define ROUTE_CACHE_LIMIT 1000 // This is defaut count of routes in the router class obecjt. #define ROUTE_CACHE_LIMIT 1000 // This is defaut count of routes in the router class obecjt.
#define TRANSPORT_PACKAGES_CACHE 1000 // This is defaut count of processed packages in the router class obecjt. #define TRANSPORT_PACKAGES_CACHE 1000 // This is defaut count of processed packages in the router class obecjt.

@ -173,6 +173,32 @@ QString DataBase::dbLocation() const {
return ""; return "";
} }
QString DataBase::backUp(int version) const {
auto&& params = defaultDbParams();
if (params.value(QH_DB_DRIVER) != "QSQLITE")
return {};
QString&& path = params.value(QH_DB_BACKUP_PATH).toString();
if (path.isEmpty()) {
return {};
}
auto file = path + "/DBv%0_" + QDateTime::currentDateTimeUtc().toString("hh:mm:ss_dd_MM_yyyy") + ".db";
file = file.arg(version);
if (db() && db()->writer() &&
QFile::exists(db()->writer()->databaseLocation())) {
QDir().mkpath(path);
if (!QFile::copy(db()->writer()->databaseLocation(), file)) {
return {};
}
}
return file;
}
ISqlDB *DataBase::db() const { ISqlDB *DataBase::db() const {
return _db; return _db;
} }
@ -254,7 +280,9 @@ bool DataBase::upgradeDataBase() {
return true; return true;
} }
void DataBase::onBeforeDBUpgrade(int , int ) const { } void DataBase::onBeforeDBUpgrade(int currentVerion, int ) const {
backUp(currentVerion);
}
const QString &DataBase::localNodeName() const { const QString &DataBase::localNodeName() const {
return _localNodeName; return _localNodeName;
@ -267,8 +295,9 @@ void DataBase::setLocalNodeName(const QString &newLocalNodeName) {
QVariantMap DataBase::defaultDbParams() const { QVariantMap DataBase::defaultDbParams() const {
return { return {
{"DBDriver", "QSQLITE"}, {QH_DB_DRIVER, "QSQLITE"},
{"DBFilePath", DEFAULT_DB_PATH + "/" + localNodeName() + "/" + localNodeName() + "_" + DEFAULT_DB_NAME}, {QH_DB_FILE_PATH, DEFAULT_DB_PATH + "/" + localNodeName() + "/" + QCoreApplication::applicationName() + "_" + DEFAULT_DB_NAME},
{QH_DB_BACKUP_PATH, DEFAULT_DB_PATH + "/" + localNodeName() + "/BackUp"}
}; };
} }
} }

@ -119,6 +119,13 @@ signals:
protected: protected:
/**
* @brief backUp This method make a backup of database.
* @param version This is current version of db.
* @return path to backupped db.
*/
QString backUp(int version) const;
/** /**
* @brief localNodeName This method return local node name. * @brief localNodeName This method return local node name.
* @return local node name * @return local node name
@ -285,6 +292,7 @@ protected:
* @see DataBase::addDBPatch * @see DataBase::addDBPatch
*/ */
virtual void onBeforeDBUpgrade(int currentVerion, int tergetVersion) const; virtual void onBeforeDBUpgrade(int currentVerion, int tergetVersion) const;
private: private:
/** /**
* @brief workWithSubscribe This method work with subscribe commnads. * @brief workWithSubscribe This method work with subscribe commnads.

@ -163,13 +163,14 @@ protected:
* *
* Support parameters of database: * Support parameters of database:
* *
* - DBDriver - This is sql driver of data base for more information see The Qt Documentations https://doc.qt.io/qt-5/sql-driver.html * - DBDriver - This is sql driver of data base for more information see The Qt Documentations https://doc.qt.io/qt-5/sql-driver.html (or QH_DB_DRIVER)
* - DBFilePath - This is path to file of data base (sqlite only). This is phusical location of sqlite database. * - DBFilePath - This is path to file of data base (sqlite only). This is phusical location of sqlite database. Or (QH_DB_FILE_PATH)
* - DBInitFile - This is sql file with sql code (structure) with default structure of the database. * - DBInitFile - This is sql file with sql code (structure) with default structure of the database. Or (QH_DB_INIT_FILE)
* - DBPass - This is password of a remote database. * - DBPass - This is password of a remote database. Or (QH_DB_PASS)
* - DBLogin - This is login of a remote database. * - DBLogin - This is login of a remote database. Or (QH_DB_LOGIN)
* - DBHost - This is host address of a remote database. * - DBHost - This is host address of a remote database. Or (QH_DB_HOST)
* - DBPort - port of a remote database. * - DBPort - port of a remote database. or (QH_DB_PORT)
* - DBBackUpPath - path of database backups (sqlite only). Or (QH_DB_BACKUP_PATH)
*/ */
virtual QVariantMap defaultInitPararm() const; virtual QVariantMap defaultInitPararm() const;

@ -1 +1 @@
Subproject commit 53a67709ff90b544036cb90edbfe8cb1ded6dc0b Subproject commit 90a4284c56856f0cbdb1a7af151d575a468c59eb