load sellers
This commit is contained in:
parent
300c883fdc
commit
90e132bcc8
4 changed files with 43 additions and 4 deletions
|
@ -397,5 +397,41 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
|||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers)
|
||||
{
|
||||
int retCode{};
|
||||
int count{};
|
||||
sqlite3_stmt* stmt;
|
||||
|
||||
retCode = sqlite3_prepare_v2(db_,
|
||||
"SELECT id, seller_no, first_name, last_name, "
|
||||
"num_offered_articles FROM sellers ORDER BY seller_no",
|
||||
-1, &stmt, nullptr);
|
||||
if (retCode != SQLITE_OK)
|
||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
||||
sellers.clear();
|
||||
|
||||
while (retCode != SQLITE_DONE) {
|
||||
++count;
|
||||
auto seller = std::make_unique<Seller>();
|
||||
seller->setUuidFromString(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
|
||||
seller->setSellerNo(sqlite3_column_int(stmt, 1));
|
||||
seller->setFirstName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
|
||||
seller->setLastName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)));
|
||||
seller->setNumArticlesOffered(sqlite3_column_int(stmt, 4));
|
||||
seller->setState(Seller::State::OK);
|
||||
sellers.push_back(std::move(seller));
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return count;
|
||||
}
|
|
@ -17,6 +17,7 @@ class Database
|
|||
Database& operator=(const Database&) = delete;
|
||||
void exec(const std::string& sql);
|
||||
unsigned int storeSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
||||
unsigned int loadSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
||||
|
||||
private:
|
||||
sqlite3* db_{nullptr};
|
||||
|
|
|
@ -12,13 +12,15 @@ Marketplace::Marketplace()
|
|||
|
||||
void Marketplace::storeToDb()
|
||||
{
|
||||
//const std::string DB_PATH{"/tmp/kima2.db"};
|
||||
|
||||
Database db;
|
||||
db.storeSellers(sellers_);
|
||||
}
|
||||
|
||||
void Marketplace::loadFromDb() {}
|
||||
void Marketplace::loadFromDb()
|
||||
{
|
||||
Database db;
|
||||
db.loadSellers(sellers_);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Seller>>& Marketplace::getSellers() { return sellers_; }
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ void MainWindow::on_actionEditSeller_triggered()
|
|||
STATUSBAR_TIMEOUT);
|
||||
} else {
|
||||
marketplace_->loadFromDb();
|
||||
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten <b>verworfen</b>.",
|
||||
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
|
||||
STATUSBAR_TIMEOUT);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue