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"); }
|
||||
|
||||
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 count{};
|
||||
|
@ -181,7 +181,7 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
|||
beginTransaction();
|
||||
|
||||
for (auto& seller : sellers) {
|
||||
if (seller->getState() == Seller::State::NEW) {
|
||||
if (seller->getState() == Seller::State::NEW && !onlyDelete) {
|
||||
retCode = sqlite3_prepare_v2(
|
||||
db_,
|
||||
"INSERT INTO sellers"
|
||||
|
@ -214,7 +214,7 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
|||
}
|
||||
++count;
|
||||
sqlite3_finalize(stmt);
|
||||
} else if (seller->getState() == Seller::State::UPDATE) {
|
||||
} else if (seller->getState() == Seller::State::UPDATE && !onlyDelete) {
|
||||
retCode = sqlite3_prepare_v2(
|
||||
db_,
|
||||
"UPDATE sellers SET"
|
||||
|
|
|
@ -16,7 +16,7 @@ class Database
|
|||
Database(const Database&) = delete;
|
||||
Database& operator=(const Database&) = delete;
|
||||
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);
|
||||
|
||||
private:
|
||||
|
|
|
@ -10,10 +10,10 @@ Marketplace::Marketplace()
|
|||
sellers_.push_back(std::move(seller));
|
||||
}
|
||||
|
||||
void Marketplace::storeToDb()
|
||||
void Marketplace::storeToDb(bool onlyDelete)
|
||||
{
|
||||
Database db;
|
||||
db.storeSellers(sellers_);
|
||||
db.storeSellers(sellers_, onlyDelete);
|
||||
}
|
||||
|
||||
void Marketplace::loadFromDb()
|
||||
|
|
|
@ -11,7 +11,7 @@ class Marketplace
|
|||
{
|
||||
public:
|
||||
Marketplace();
|
||||
void storeToDb();
|
||||
void storeToDb(bool onlyDelete = false);
|
||||
void loadFromDb();
|
||||
std::vector<std::unique_ptr<Seller>>& getSellers();
|
||||
int getNextSellerNo();
|
||||
|
|
|
@ -149,7 +149,7 @@ bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
|
|||
} else {
|
||||
emit beginRemoveRows(parent, row, row + count - 1);
|
||||
seller->setState(Seller::State::DELETE);
|
||||
marketplace_->storeToDb();
|
||||
marketplace_->storeToDb(true);
|
||||
emit endRemoveRows();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue