* Add early shared account support (Database schema has changed)
* Update TODO
This commit is contained in:
@@ -31,6 +31,7 @@ public:
|
||||
wxString number;
|
||||
bool shared;
|
||||
bool _default;
|
||||
bool is_owner;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -272,6 +272,23 @@ User* Database::LoadUser(const wxString& name)
|
||||
account.number = set.GetAsString(wxT("number"));
|
||||
account.shared = set.GetBool(wxT("shared"));
|
||||
account._default = set.GetBool(wxT("default_account"));
|
||||
account.is_owner = true;
|
||||
user->_accounts.push_back(account);
|
||||
}
|
||||
set.Finalize();
|
||||
|
||||
req = wxT("SELECT * FROM account WHERE id IN (SELECT id FROM shared_account WHERE user='") + user->_id + wxT("') ORDER BY name ASC");
|
||||
|
||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||
|
||||
while (set.NextRow())
|
||||
{
|
||||
account.id = set.GetAsString(wxT("id"));
|
||||
account.name = set.GetAsString(wxT("name"));
|
||||
account.number = set.GetAsString(wxT("number"));
|
||||
account.shared = set.GetBool(wxT("shared"));
|
||||
account._default = set.GetBool(wxT("default_account"));
|
||||
account.is_owner = false;
|
||||
user->_accounts.push_back(account);
|
||||
}
|
||||
set.Finalize();
|
||||
@@ -677,12 +694,55 @@ void Database::UpdateAccount(Account& ac)
|
||||
req += wxT(" WHERE id='") + ac.id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
|
||||
if (!ac.shared && ac.is_owner)
|
||||
{
|
||||
req = wxT("DELETE FROM shared_account WHERE id='") + ac.id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
}
|
||||
|
||||
void Database::DeleteAccount(Account& ac)
|
||||
void Database::DeleteAccount(User* user, Account& ac)
|
||||
{
|
||||
wxString req;
|
||||
req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'");
|
||||
wxSQLite3ResultSet set;
|
||||
|
||||
if (ac.is_owner)
|
||||
{
|
||||
if (ac.shared)
|
||||
{
|
||||
req = wxT("DELETE FROM shared_account WHERE id='") + ac.id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
else
|
||||
{
|
||||
req = wxT("DELETE FROM shared_account WHERE user='") + user->_id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
|
||||
req = wxT("SELECT COUNT(user) AS cnt FROM shared_account WHERE id='") + ac.id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_QUERY(req, set, );
|
||||
|
||||
if (!set.GetInt(wxT("cnt")))
|
||||
{
|
||||
ac.shared = false;
|
||||
UpdateAccount(ac);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Database::AddSharedAccount(Account& ac, const wxString& granted)
|
||||
{
|
||||
wxString req;
|
||||
|
||||
req = wxT("INSERT INTO shared_account ('id', 'user') VALUES ('") + ac.id + wxT("', '") + granted + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ public:
|
||||
|
||||
wxString AddAccount(User* user, Account& ac);
|
||||
void UpdateAccount(Account& ac);
|
||||
void DeleteAccount(Account& ac);
|
||||
void DeleteAccount(User* user, Account& ac);
|
||||
void AddSharedAccount(Account& ac, const wxString& granted);
|
||||
|
||||
wxString AddCategory(User* user, Category& category);
|
||||
void UpdateCategory(Category& category);
|
||||
|
||||
Reference in New Issue
Block a user