|
|
|
@ -15,7 +15,7 @@ Database::Database()
|
|
|
|
|
{ |
|
|
|
|
namespace fs = std::filesystem; |
|
|
|
|
|
|
|
|
|
#if defined(__linux__) || defined (__APPLE__) |
|
|
|
|
#if defined(__linux__) || defined(__APPLE__) |
|
|
|
|
fs::path dbpath = fs::path(std::getenv("HOME")) / ".local/share/kima2"; |
|
|
|
|
#elif defined(_WIN64) || defined(_WIN32) |
|
|
|
|
fs::path dbpath = fs::path(std::getenv("LOCALAPPDATA") / "/kima2"; |
|
|
|
@ -435,5 +435,39 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
|
|
|
|
|
|
|
|
|
sqlite3_finalize(stmt); |
|
|
|
|
|
|
|
|
|
for (auto& seller : sellers) { |
|
|
|
|
retCode = sqlite3_prepare_v2(db_, |
|
|
|
|
"SELECT id, source_no, article_no, description, price" |
|
|
|
|
" FROM articles" |
|
|
|
|
" WHERE seller_id = :seller_uuid" |
|
|
|
|
" ORDER BY article_no", |
|
|
|
|
-1, &stmt, nullptr); |
|
|
|
|
if (retCode != SQLITE_OK) |
|
|
|
|
throw std::runtime_error(sqlite3_errmsg(db_)); |
|
|
|
|
|
|
|
|
|
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_uuid"), |
|
|
|
|
boost::uuids::to_string(seller->getUuid()).c_str(), -1, SQLITE_TRANSIENT); |
|
|
|
|
|
|
|
|
|
retCode = sqlite3_step(stmt); |
|
|
|
|
|
|
|
|
|
while (retCode != SQLITE_DONE) { |
|
|
|
|
++count; |
|
|
|
|
auto article = std::make_unique<Article>(); |
|
|
|
|
article->setUuidFromString(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))); |
|
|
|
|
article->setSeller(seller.get()); |
|
|
|
|
article->setSourceNo(sqlite3_column_int(stmt, 1)); |
|
|
|
|
article->setArticleNo(sqlite3_column_int(stmt, 2)); |
|
|
|
|
article->setDescription(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3))); |
|
|
|
|
article->setPrice(sqlite3_column_int(stmt, 4)); |
|
|
|
|
article->setState(Article::State::OK); |
|
|
|
|
|
|
|
|
|
seller->addArticle(std::move(article)); |
|
|
|
|
|
|
|
|
|
retCode = sqlite3_step(stmt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sqlite3_finalize(stmt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return count; |
|
|
|
|
} |