Browse Source

Now we can decide to make only-delete-changes in the db

allow_new_sellers
Martin Brodbeck 4 years ago
parent
commit
33f24ab7be
  1. 6
      src/core/database.cpp
  2. 2
      src/core/database.h
  3. 4
      src/core/marketplace.cpp
  4. 2
      src/core/marketplace.h
  5. 2
      src/gui/sellermodel.cpp

6
src/core/database.cpp

@ -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"

2
src/core/database.h

@ -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:

4
src/core/marketplace.cpp

@ -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()

2
src/core/marketplace.h

@ -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();

2
src/gui/sellermodel.cpp

@ -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…
Cancel
Save