[Fix #4] Archive current db when creating new
This commit is contained in:
parent
271aac0914
commit
cfc632a986
3 changed files with 26 additions and 3 deletions
|
@ -5,6 +5,8 @@
|
|||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
Database::Database(const std::string& dbname)
|
||||
{
|
||||
dbname_ = dbname;
|
||||
|
@ -30,11 +32,26 @@ Database::Database()
|
|||
throw err;
|
||||
}
|
||||
}
|
||||
dbpath /= "kima2-cpp.db";
|
||||
dbpath /= "kima2.db";
|
||||
dbname_ = dbpath.string();
|
||||
init();
|
||||
}
|
||||
|
||||
void Database::newDb()
|
||||
{
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
fs::path sourcePath = dbname_;
|
||||
fs::path destPath = sourcePath.parent_path() / sourcePath.stem();
|
||||
destPath += std::string("_") += boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time()) += ".db";
|
||||
|
||||
fs::copy_file(sourcePath, destPath, fs::copy_options::overwrite_existing);
|
||||
|
||||
fs::remove(sourcePath);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
Database::~Database() { sqlite3_close(db_); }
|
||||
|
||||
void Database::exec(const std::string& sql)
|
||||
|
|
|
@ -24,6 +24,7 @@ class Database
|
|||
unsigned int loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
||||
std::vector<std::unique_ptr<Seller>>& sellers);
|
||||
void updateCashPointNo(int oldCashPointNo, int newCashPointNo);
|
||||
void newDb();
|
||||
|
||||
private:
|
||||
sqlite3* db_{nullptr};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <iomanip>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
@ -272,7 +273,7 @@ std::string escapeCsvValue(const std::string& value, const char delimiter)
|
|||
|
||||
void Marketplace::clear()
|
||||
{
|
||||
std::for_each(sellers_.begin(), sellers_.end(), [](auto& seller) {
|
||||
/* std::for_each(sellers_.begin(), sellers_.end(), [](auto& seller) {
|
||||
if (seller->getUuidAsString() == "11111111-1111-1111-1111-111111111111") {
|
||||
for (auto& article : seller->getArticles()) {
|
||||
article->setState(Article::State::DELETE);
|
||||
|
@ -283,5 +284,9 @@ void Marketplace::clear()
|
|||
});
|
||||
std::for_each(sales_.begin(), sales_.end(),
|
||||
[](auto& sale) { sale->setState(Sale::State::DELETE); });
|
||||
storeToDb();
|
||||
storeToDb(); */
|
||||
|
||||
Database db;
|
||||
db.newDb();
|
||||
loadFromDb();
|
||||
}
|
Loading…
Reference in a new issue