2018-07-06 13:30:23 +02:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
#define DATABASE_H
|
|
|
|
|
2018-07-25 09:31:17 +02:00
|
|
|
#include "sale.h"
|
2018-07-11 15:58:09 +02:00
|
|
|
#include "seller.h"
|
|
|
|
|
2018-07-06 13:30:23 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
class Database
|
|
|
|
{
|
2022-07-07 15:21:46 +02:00
|
|
|
public:
|
|
|
|
enum class InitResult { OK, OUTDATED_REPLACED };
|
|
|
|
explicit Database(const std::string &dbname);
|
2018-07-17 10:19:41 +02:00
|
|
|
Database();
|
2018-07-06 13:30:23 +02:00
|
|
|
~Database();
|
2022-07-07 15:21:46 +02:00
|
|
|
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,
|
2018-07-25 09:31:17 +02:00
|
|
|
bool onlyDelete = false);
|
2022-07-07 15:21:46 +02:00
|
|
|
unsigned int loadSellers(std::vector<std::unique_ptr<Seller>> &sellers);
|
|
|
|
unsigned int storeSales(std::vector<std::unique_ptr<Sale>> &sales);
|
|
|
|
unsigned int loadSales(std::vector<std::unique_ptr<Sale>> &sales,
|
|
|
|
std::vector<std::unique_ptr<Seller>> &sellers);
|
2018-07-30 13:40:58 +02:00
|
|
|
void updateCashPointNo(int oldCashPointNo, int newCashPointNo);
|
2018-10-08 10:48:28 +02:00
|
|
|
void newDb();
|
2022-07-07 15:21:46 +02:00
|
|
|
InitResult getInitResult() { return initResult_; }
|
2018-07-13 13:05:19 +02:00
|
|
|
|
2022-07-07 15:21:46 +02:00
|
|
|
private:
|
|
|
|
sqlite3 *db_{nullptr};
|
2018-07-11 09:43:40 +02:00
|
|
|
std::string dbname_;
|
2018-07-17 10:19:41 +02:00
|
|
|
void init();
|
2018-07-09 21:03:59 +02:00
|
|
|
void beginTransaction();
|
|
|
|
void endTransaction();
|
2018-07-11 09:43:40 +02:00
|
|
|
void createNew();
|
|
|
|
int getVersion();
|
2022-07-07 15:21:46 +02:00
|
|
|
unsigned int storeArticles(std::vector<Article *> articles);
|
2018-08-07 07:57:47 +02:00
|
|
|
void updateDbToVer2();
|
2019-10-04 15:15:43 +02:00
|
|
|
void updateDbToVer3();
|
2019-10-04 15:50:13 +02:00
|
|
|
InitResult initResult_{InitResult::OK};
|
2018-07-06 13:30:23 +02:00
|
|
|
};
|
|
|
|
|
2019-10-04 15:15:43 +02:00
|
|
|
#endif // DATABASE_H
|