37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
#include "headers/Admin.h"
|
|
using std::to_string;
|
|
|
|
Admin::Admin(string name_, string password_)
|
|
: id{auto_increment_db() + 1}, name{name_}, password{hash_password(password_)} {
|
|
save_db();
|
|
}
|
|
|
|
Admin::Admin(int id_, string name_, string password_) : id{id_}, name{name_}, password{password_} {}
|
|
|
|
void Admin::save_db() {
|
|
string statement{"insert into Admin values (, '', '');"};
|
|
statement.insert(33, password);
|
|
statement.insert(29, name);
|
|
statement.insert(26, to_string(id));
|
|
SQLite::Transaction transaction(data::db);
|
|
data::db.exec(statement);
|
|
transaction.commit();
|
|
}
|
|
|
|
void Admin::update_db() {
|
|
string statement = "UPDATE Admin SET name = '', password = '' where id = '';";
|
|
statement.insert(54, to_string(id));
|
|
statement.insert(40, password);
|
|
statement.insert(25, name);
|
|
data::db.exec(statement);
|
|
}
|
|
|
|
int Admin::auto_increment_db() {
|
|
SQLite::Statement max_id(data::db, "select max(id) from Admin;");
|
|
int id = 0;
|
|
max_id.executeStep();
|
|
id = max_id.getColumn(0);
|
|
max_id.reset();
|
|
return id;
|
|
}
|