First pass
This commit is contained in:
@@ -21,8 +21,9 @@
|
||||
#define DATABASE_H
|
||||
|
||||
#include <list>
|
||||
#include <wx/wxsqlite3.h>
|
||||
#include <wx/wx.h>
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <QDate>
|
||||
|
||||
#include <controller/KissCount.hpp>
|
||||
#include "model.hpp"
|
||||
@@ -40,40 +41,31 @@
|
||||
// }
|
||||
|
||||
#define EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
|
||||
do{ \
|
||||
try \
|
||||
{ \
|
||||
_db.ExecuteUpdate(req); \
|
||||
} \
|
||||
catch (wxSQLite3Exception e) \
|
||||
{ \
|
||||
wxMessageBox(_("Update failed !\n") + req, _("Error"), wxICON_ERROR | wxOK); \
|
||||
std::cerr << __FUNCTION__ << "\n" ; \
|
||||
std::cerr << req.mb_str() << "\n" ; \
|
||||
std::cerr << e.GetMessage().mb_str() << "\n" ; \
|
||||
code_if_fail; \
|
||||
return return_value; \
|
||||
} \
|
||||
do { \
|
||||
QSqlQuery query; \
|
||||
if (!query.exec(req)) \
|
||||
{ \
|
||||
QMessageBox::critical(0, _("Error"), _("Update failed !\n") + req); \
|
||||
std::cerr << __FUNCTION__ << "\n" ; \
|
||||
std::cerr << req.toStdString() << "\n" ; \
|
||||
std::cerr << query.lastError().text().toStdString() << "\n" ; \
|
||||
code_if_fail; \
|
||||
return return_value; \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define EXECUTE_SQL_QUERY_WITH_CODE(req, res, return_value, code_if_fail, code_if_syntax_fail) \
|
||||
do{ \
|
||||
try \
|
||||
{ \
|
||||
res = _db.ExecuteQuery(req); \
|
||||
} \
|
||||
catch (wxSQLite3Exception e) \
|
||||
{ \
|
||||
wxMessageBox(_("Query failed !\n") + req, _("Error"), wxICON_ERROR | wxOK); \
|
||||
std::cerr << __FUNCTION__ << "\n" ; \
|
||||
std::cerr << req.mb_str() << "\n" ; \
|
||||
std::cerr << e.GetMessage().mb_str() << "\n" ; \
|
||||
code_if_fail; \
|
||||
return return_value; \
|
||||
} \
|
||||
} while(0);
|
||||
#define EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
|
||||
if (!query.exec(req)) \
|
||||
{ \
|
||||
QMessageBox::critical(0, _("Error"), _("Query failed !\n") + req); \
|
||||
std::cerr << __FUNCTION__ << "\n" ; \
|
||||
std::cerr << req.toStdString() << "\n" ; \
|
||||
std::cerr << query.lastError().text().toStdString() << "\n" ; \
|
||||
code_if_fail; \
|
||||
return return_value; \
|
||||
} \
|
||||
|
||||
#define EXECUTE_SQL_QUERY(req, res, return_value) EXECUTE_SQL_QUERY_WITH_CODE(req, res, return_value, {}, {})
|
||||
#define EXECUTE_SQL_QUERY(req, return_value) EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, {}, {})
|
||||
|
||||
#define EXECUTE_SQL_UPDATE(req, return_value) EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, {}, {})
|
||||
|
||||
@@ -83,8 +75,8 @@ class User;
|
||||
class Database
|
||||
{
|
||||
public:
|
||||
static const int FIX_OP = 1;//(1 << 0);
|
||||
static const int NON_FIX_OP = 2;//(1 << 1);
|
||||
static const int FIX_OP = (1 << 0);
|
||||
static const int NON_FIX_OP = (1 << 1);
|
||||
static const int CHECKED_OP = (1 << 2);
|
||||
static const int NOT_CHECKED_OP = (1 << 3);
|
||||
static const int ALL_OP = (~0);
|
||||
@@ -93,64 +85,64 @@ public:
|
||||
|
||||
Database(const char* filename, KissCount* kiss);
|
||||
|
||||
std::list<wxString> GetUsers();
|
||||
bool IsValidUser(const wxString& user, const wxString& password);
|
||||
std::list<std::string> GetUsers();
|
||||
bool IsValidUser(const QString& user, const QString& password);
|
||||
|
||||
User* LoadUser(const wxString& name);
|
||||
User* LoadUser(const std::string& name);
|
||||
void LoadYear(User* user, int year);
|
||||
|
||||
void UpdateOperation(User* user, Operation& op, bool checkTransfert=true);
|
||||
wxString AddOperation(User* user, Operation& op, bool checkTransfert=true);
|
||||
int AddOperation(User* user, Operation& op, bool checkTransfert=true);
|
||||
void DeleteOperation(User* user, Operation& op);
|
||||
void DeleteOperations(User* user, int month, int year);
|
||||
bool LoadOperation(User* user, const wxString& id);
|
||||
double MetaAmount(const wxString& id);
|
||||
double MetaPositiveAmount(const wxString& id);
|
||||
bool LoadOperation(User* user, int id);
|
||||
double MetaAmount(int id);
|
||||
double MetaPositiveAmount(int id);
|
||||
|
||||
double GetAccountAmount(const wxString& id, int month, int year);
|
||||
void SetAccountAmount(const wxString& accountId, int month, int year, double amount);
|
||||
double CalcAccountAmount(const wxString& id, int month, int year, bool* had_values);
|
||||
double GetAccountAmount(int id, int month, int year);
|
||||
void SetAccountAmount(int accountId, int month, int year, double amount);
|
||||
double CalcAccountAmount(int id, int month, int year, bool* had_values);
|
||||
|
||||
wxString AddAccount(User* user, Account& ac);
|
||||
int AddAccount(User* user, Account& ac);
|
||||
void UpdateAccount(Account& ac);
|
||||
void DeleteAccount(User* user, Account& ac, const wxString& replacement);
|
||||
void AddSharedAccount(Account& ac, const wxString& granted);
|
||||
void RemoveSharedAccount(Account& ac, const wxString& granted);
|
||||
void DeleteAccount(User* user, Account& ac, int replacement);
|
||||
void AddSharedAccount(Account& ac, const std::string& granted);
|
||||
void RemoveSharedAccount(Account& ac, const std::string& granted);
|
||||
|
||||
wxString AddCategory(User* user, Category& category);
|
||||
int AddCategory(User* user, Category& category);
|
||||
void UpdateCategory(Category& category);
|
||||
void DeleteCategory(User* user, Category& category, const wxString& replacement);
|
||||
bool LoadCategory(const wxString& id, const wxString& name, Category& category);
|
||||
void DeleteCategory(User* user, Category& category, int replacement);
|
||||
bool LoadCategory(int id, const std::string& name, Category& category);
|
||||
|
||||
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
||||
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||
|
||||
void ChangePassword(User* user, const wxString& password);
|
||||
bool UserExists(const wxString& name);
|
||||
void ChangeName(User* user, const wxString& name);
|
||||
void NewUser(const wxString& name);
|
||||
void ChangePassword(User* user, const std::string& password);
|
||||
bool UserExists(const std::string& name);
|
||||
void ChangeName(User* user, const std::string& name);
|
||||
void NewUser(const std::string& name);
|
||||
|
||||
void UpdatePreference(User* user, const wxString& preference);
|
||||
void UpdatePreference(User* user, const std::string& preference);
|
||||
|
||||
std::vector<Operation>* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
|
||||
wxString* amountFrom, wxString* amountTo,
|
||||
std::vector<wxString> categories, int types, std::vector<wxString> accounts, bool wildcards);
|
||||
std::vector<Operation>* Search(User* user, std::string* description, QDate* dateFrom, QDate* dateTo,
|
||||
int* amountFrom, int* amountTo,
|
||||
std::vector<int> categories, int types, std::vector<int> accounts, bool wildcards);
|
||||
|
||||
void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
|
||||
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
|
||||
std::map<wxString, double>* categories);
|
||||
void GetStats(User* user, int monthFrom, int yearFrom, int monthTo,
|
||||
int yearTo, std::map<int, std::map<int, std::map<int, double> > >* accountAmounts,
|
||||
std::map<int, double>* categories);
|
||||
|
||||
void GetMonthStats(User* user, const wxString& month, const wxString& year, int nbDays,
|
||||
std::map<wxString, std::vector<double> >* operations,
|
||||
std::map<wxString, double>* categories);
|
||||
void GetMonthStats(User* user, int month, int year, int nbDays,
|
||||
std::map<int, std::vector<double> >* operations,
|
||||
std::map<int, double>* categories);
|
||||
|
||||
void KillMe(User* user);
|
||||
bool GetOperation(const wxString& id, Operation* op);
|
||||
std::map<wxString, wxString> getSharedAccountOwners(const wxString& account);
|
||||
wxString getSharedAccountOwner(const wxString& account);
|
||||
bool GetOperation(int id, Operation* op);
|
||||
std::map<std::string, std::string> getSharedAccountOwners(int account);
|
||||
int getSharedAccountOwner(int account);
|
||||
|
||||
std::map<wxString, double>* GetNotChecked(User* user, int month, int year);
|
||||
std::map<wxString, double>* GetVirtualAmount(User* user, int month, int year);
|
||||
std::map<int, int>* GetNotChecked(User* user, int month, int year);
|
||||
std::map<int, int>* GetVirtualAmount(User* user, int month, int year);
|
||||
|
||||
void UpdateImportPattern(User* user);
|
||||
|
||||
@@ -160,10 +152,10 @@ public:
|
||||
|
||||
private:
|
||||
KissCount* _kiss;
|
||||
wxSQLite3Database _db;
|
||||
QSqlDatabase _db;
|
||||
|
||||
void CreateDatabase();
|
||||
wxString HashPassword(const wxString& password);
|
||||
QString HashPassword(const QString& password);
|
||||
void LinkOrUnlinkOperation(User* user, Operation& op);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user