1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include "Accounts_model.h"
using namespace soci;
using namespace std;
Accounts_model::Accounts_model() : Engine_model() {
Log::trace(3, "Accounts_model - Constructeur");
Log::trace(1, "Initialisation des variables de classes [...]");
begin();
int_id = -1;
str_login = "";
str_loginCrypted = "";
str_password = "";
Log::trace(1, "Initialisation des variables de classes [OK]");
}
[...]
int Accounts_model::newAccount(){
Log::trace(3, "Accounts_model - newAccount");
Log::trace(2, "Transaction SQL : BEGIN");
transaction tr(*sql);
try{
Log::trace(1, "Insertion du nouveau compte en base [...]");
*sql << "INSERT INTO Accounts(login, loginCrypted, password, type) VALUES(:login, :loginCrypted, :password, :type)", use(str_login), use(str_loginCrypted), use(str_password), use(int_type);
Log::trace(1, "Insertion du nouveau compte en base [OK]");
}
catch(std::exception const &e){
Log::trace(2, "Transaction SQL : ROLLBACK");
tr.rollback();
Log::trace(6, "Insertion du nouveau compte en base [ERREUR]");
Log::trace(6, e.what());
return -1;
}
int int_id;
try{
Log::trace(1, "Récupération de l'id du compte inséré [...]");
*sql << "SELECT id FROM Accounts WHERE login = :login", use(str_login), into(int_id);
Log::trace(1, "Récupération de l'id du compte inséré [OK]");
}
catch(std::exception const &e){
Log::trace(2, "Transaction SQL : ROLLBACK");
tr.rollback();
Log::trace(6, "Récupération de l'id du compte inséré [ERREUR]");
Log::trace(6, e.what());
return -2;
}
Log::trace(2, "Transaction SQL : COMMIT");
tr.commit();
return int_id;
}
[...] |
Partager