Revision 126e71e3
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
samples/example/main.cpp | ||
---|---|---|
// CuteEntityManager::EntityManager("QSQLITE",
|
||
// QDir::currentPath() + "/db.sqlite", "", "", "", 0, true);
|
||
CuteEntityManager::EntityManager("QSQLITE",
|
||
":memory:","","","","",true);
|
||
":memory:", "", "", "", "", true);
|
||
SqliteBackupProcessor *sqliteproc = new SqliteBackupProcessor(e->getDb(),
|
||
QDir::currentPath());
|
||
qWarning() << "DB Loaded:" << sqliteproc->sqliteDBMemFile(false, "db.sqlite");
|
src/sqlitebackupprocessor.cpp | ||
---|---|---|
*/
|
||
#include "sqlitebackupprocessor.h"
|
||
#include <sqlite3.h>
|
||
|
||
#include <QFileInfoList>
|
||
using namespace CuteEntityManager;
|
||
SqliteBackupProcessor::SqliteBackupProcessor(QSharedPointer<Database> database,
|
||
QString destination) : QObject() {
|
||
... | ... | |
void SqliteBackupProcessor::setDatabase(const QSharedPointer<Database> &value) {
|
||
database = value;
|
||
}
|
||
|
||
QString SqliteBackupProcessor::getDestination() const {
|
||
return destination;
|
||
}
|
||
... | ... | |
|
||
void SqliteBackupProcessor::backup() {
|
||
QString fileName = this->destination + "/" + this->getBackupFilename();
|
||
if (incrementalBackups) {
|
||
fileName += QString::number(counter);
|
||
++counter;
|
||
if (this->incrementalBackups) {
|
||
this->rotateBackup();
|
||
if (this->counter > 0) {
|
||
fileName += "." + QString::number(this->counter);
|
||
}
|
||
if (this->counter < this->backupCount) {
|
||
++this->counter;
|
||
}
|
||
}
|
||
this->sqliteDBMemFile(true, fileName);
|
||
}
|
||
|
||
void SqliteBackupProcessor::rotateBackup() {
|
||
if (this->counter == this->backupCount) {
|
||
QStringList nameFilter = QStringList(this->getBackupFilename());
|
||
QDir directory = QDir(this->destination);
|
||
QFileInfoList files = directory.entryInfoList(nameFilter);
|
||
for (int var = 0; var < files.size(); ++var) {
|
||
QFileInfo file = files.at(var);
|
||
if (file.isFile()) {
|
||
int lastIndex = file.filePath().lastIndexOf(".");
|
||
if (lastIndex > -1) {
|
||
QString sub = file.filePath().mid(lastIndex);
|
||
bool ok = false;
|
||
int num = sub.toInt(&ok);
|
||
QDir dir = QDir();
|
||
if (ok) {
|
||
if (num == 1) {
|
||
dir.rename(file.filePath(), file.path().mid(0, lastIndex));
|
||
} else {
|
||
dir.rename(file.filePath(), file.path().mid(0, lastIndex) + QString(num - 1));
|
||
}
|
||
} else {
|
||
dir.remove(file.filePath());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
QSharedPointer<QTimer> SqliteBackupProcessor::getTimer() const {
|
||
return timer;
|
||
}
|
||
... | ... | |
timer = value;
|
||
}
|
||
|
||
|
||
bool SqliteBackupProcessor::getIncrementalBackups() const {
|
||
return incrementalBackups;
|
||
}
|
src/sqlitebackupprocessor.h | ||
---|---|---|
#include <QString>
|
||
#include <QVariant>
|
||
#include <QTimer>
|
||
#include <QDir>
|
||
#include "database.h"
|
||
namespace CuteEntityManager {
|
||
class SqliteBackupProcessor : public QObject {
|
||
public:
|
||
explicit SqliteBackupProcessor(QSharedPointer<Database> database,
|
||
QString destination);
|
||
/**
|
||
* @brief SqliteBackupProcessor
|
||
* @param database
|
||
* @param destination
|
||
* @param backupFilename
|
||
* @param timer
|
||
* @param incrementalBackups
|
||
* @param backupCount
|
||
* You must start the timer.
|
||
*/
|
||
explicit SqliteBackupProcessor(QSharedPointer<Database> database,
|
||
QString destination, QString backupFilename, QSharedPointer<QTimer> timer,
|
||
bool incrementalBackups = false, int backupCount = 1);
|
||
... | ... | |
QSharedPointer<QTimer> getTimer() const;
|
||
void setTimer(const QSharedPointer<QTimer> &value);
|
||
|
||
public slots:
|
||
public slots:
|
||
bool sqliteDBMemFile(bool save, QString fileName = "db.sqlite.bak");
|
||
void backup();
|
||
protected slots:
|
||
void rotateBackup();
|
||
|
||
private:
|
||
QSharedPointer<Database> database;
|
||
QString destination;
|
Auch abrufbar als: Unified diff
backup rotate