Now we can decide to make only-delete-changes in the db
This commit is contained in:
parent
de95d5f341
commit
33f24ab7be
5 changed files with 8 additions and 8 deletions
|
@ -172,7 +172,7 @@ void Database::beginTransaction() { exec("BEGIN TRANSACTION"); }
|
||||||
|
|
||||||
void Database::endTransaction() { exec("END TRANSACTION"); }
|
void Database::endTransaction() { exec("END TRANSACTION"); }
|
||||||
|
|
||||||
unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& sellers)
|
unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& sellers, bool onlyDelete)
|
||||||
{
|
{
|
||||||
int retCode{};
|
int retCode{};
|
||||||
int count{};
|
int count{};
|
||||||
|
@ -181,7 +181,7 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
|
|
||||||
for (auto& seller : sellers) {
|
for (auto& seller : sellers) {
|
||||||
if (seller->getState() == Seller::State::NEW) {
|
if (seller->getState() == Seller::State::NEW && !onlyDelete) {
|
||||||
retCode = sqlite3_prepare_v2(
|
retCode = sqlite3_prepare_v2(
|
||||||
db_,
|
db_,
|
||||||
"INSERT INTO sellers"
|
"INSERT INTO sellers"
|
||||||
|
@ -214,7 +214,7 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
} else if (seller->getState() == Seller::State::UPDATE) {
|
} else if (seller->getState() == Seller::State::UPDATE && !onlyDelete) {
|
||||||
retCode = sqlite3_prepare_v2(
|
retCode = sqlite3_prepare_v2(
|
||||||
db_,
|
db_,
|
||||||
"UPDATE sellers SET"
|
"UPDATE sellers SET"
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Database
|
||||||
Database(const Database&) = delete;
|
Database(const Database&) = delete;
|
||||||
Database& operator=(const Database&) = delete;
|
Database& operator=(const Database&) = delete;
|
||||||
void exec(const std::string& sql);
|
void exec(const std::string& sql);
|
||||||
unsigned int storeSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
unsigned int storeSellers(std::vector<std::unique_ptr<Seller>>& sellers, bool onlyDelete = false);
|
||||||
unsigned int loadSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
unsigned int loadSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -10,10 +10,10 @@ Marketplace::Marketplace()
|
||||||
sellers_.push_back(std::move(seller));
|
sellers_.push_back(std::move(seller));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::storeToDb()
|
void Marketplace::storeToDb(bool onlyDelete)
|
||||||
{
|
{
|
||||||
Database db;
|
Database db;
|
||||||
db.storeSellers(sellers_);
|
db.storeSellers(sellers_, onlyDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::loadFromDb()
|
void Marketplace::loadFromDb()
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Marketplace
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Marketplace();
|
Marketplace();
|
||||||
void storeToDb();
|
void storeToDb(bool onlyDelete = false);
|
||||||
void loadFromDb();
|
void loadFromDb();
|
||||||
std::vector<std::unique_ptr<Seller>>& getSellers();
|
std::vector<std::unique_ptr<Seller>>& getSellers();
|
||||||
int getNextSellerNo();
|
int getNextSellerNo();
|
||||||
|
|
|
@ -149,7 +149,7 @@ bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||||
} else {
|
} else {
|
||||||
emit beginRemoveRows(parent, row, row + count - 1);
|
emit beginRemoveRows(parent, row, row + count - 1);
|
||||||
seller->setState(Seller::State::DELETE);
|
seller->setState(Seller::State::DELETE);
|
||||||
marketplace_->storeToDb();
|
marketplace_->storeToDb(true);
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue