database request to retrieve a freelancers id

This commit is contained in:
Tina_Azure
2023-04-22 23:20:34 +02:00
parent 83a22321ca
commit 49e3faf722

View File

@ -64,6 +64,11 @@ namespace Database {
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_SALT = "selectFreelancerSalt";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_SALT = "select salt from freelancers where emailaddress = $1;";
/*
* Name and Statement for prepared statement to get id using a given email
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_ID = "selectFreelancerSalt";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_ID = "select id from freelancers where emailaddress = $1;";
/*
* Name and Statement for prepared statement to check if hash is valid
@ -353,6 +358,17 @@ namespace Database {
connection.unprepare(PREPARED_STATEMENT_SELECT_FREELANCER_SALT);
return result;
}
/*
* Executes the prepared statement SELECT_FREELANCER_ID
* Takes an open pqxx::connection and the id to select by
*/
pqxx::result executePreparedStatement_SELECT_FREELANCER_ID(pqxx::connection &connection, const std::string& freelancerEmail) {
connection.prepare(PREPARED_STATEMENT_SELECT_FREELANCER_ID, SQL_STATEMENT_SELECT_FREELANCER_ID);
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_FREELANCER_ID, freelancerEmail);
work.commit();
connection.unprepare(PREPARED_STATEMENT_SELECT_FREELANCER_ID);
return result;
}