Database handler to create new freelancer
This commit is contained in:
@ -21,6 +21,12 @@ namespace Database {
|
|||||||
const static std::string PREPARED_STATEMENT_INSERT_ITEM_IN_REQUESTS = "insertItemInRequests";
|
const static std::string PREPARED_STATEMENT_INSERT_ITEM_IN_REQUESTS = "insertItemInRequests";
|
||||||
const static std::string SQL_STATEMENT_INSERT_ITEM_IN_REQUESTS = "INSERT INTO requests(id, customerEmailAddress, freelancerid , templateid , currencyPreference, priceUpFront, priceOnDeliver, requestDescription, accepted, upFrontInvoiceID, onDeliverInvoiceID, upFrontPaid, onDeliverPaid, completed, customerContactDetails, customerName) VALUES(DEFAULT, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);";
|
const static std::string SQL_STATEMENT_INSERT_ITEM_IN_REQUESTS = "INSERT INTO requests(id, customerEmailAddress, freelancerid , templateid , currencyPreference, priceUpFront, priceOnDeliver, requestDescription, accepted, upFrontInvoiceID, onDeliverInvoiceID, upFrontPaid, onDeliverPaid, completed, customerContactDetails, customerName) VALUES(DEFAULT, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name and Statement for prepared statement to create a new freelancer
|
||||||
|
*/
|
||||||
|
const static std::string PREPARED_STATEMENT_INSERT_NEW_FREELANCER = "insertNewFreelancer";
|
||||||
|
const static std::string SQL_STATEMENT_INSERT_NEW_FREELANCER = "INSERT INTO freelancers (emailaddress, name, salt, hash) values($1, $2, $3, $4);";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Name and Statement for prepared statement to select an item based on a given ID
|
* Name and Statement for prepared statement to select an item based on a given ID
|
||||||
* Case for boolean return values because the default return value is f/t instead of 0/1 or false/true
|
* Case for boolean return values because the default return value is f/t instead of 0/1 or false/true
|
||||||
@ -214,6 +220,34 @@ namespace Database {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Executes the prepared statement INSERT_NEW_FREELANCER
|
||||||
|
* Takes an open pqxx::connection and the name, email, salt and hash
|
||||||
|
* returns errorLevel
|
||||||
|
* 0 = no error
|
||||||
|
* 1 = query error
|
||||||
|
* 2 = critical error
|
||||||
|
*/
|
||||||
|
int executePreparedStatement_INSERT_NEW_FREELANCER(pqxx::connection &connection, std::string email, std::string name, std::string salt, std::string hash) {
|
||||||
|
try {
|
||||||
|
connection.prepare(PREPARED_STATEMENT_INSERT_NEW_FREELANCER, SQL_STATEMENT_INSERT_NEW_FREELANCER);
|
||||||
|
pqxx::work work(connection);
|
||||||
|
work.exec_prepared(PREPARED_STATEMENT_INSERT_NEW_FREELANCER, email, name, salt, hash);
|
||||||
|
work.commit();
|
||||||
|
}
|
||||||
|
catch (pqxx::sql_error const &e) {
|
||||||
|
std::cerr
|
||||||
|
<< "Database error: " << e.what() << std::endl
|
||||||
|
<< "Query was: " << e.query() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (std::exception const &e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Executes the prepared statement SELECT_ITEM_BY_ID
|
* Executes the prepared statement SELECT_ITEM_BY_ID
|
||||||
* Takes an open pqxx::connection
|
* Takes an open pqxx::connection
|
||||||
|
Reference in New Issue
Block a user