Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../../include/warehouseData/dataBase.h"
- void whData::initDB() {
- conn = PQconnectdb("host='dbm.fe.up.pt' user='siem1719' password='ii.2018' dbname='siem1719' port='5432'");
- if (!conn) {
- cout << "Failed to connect to the database" << endl;
- exit(-1);
- }
- if (PQstatus(conn) != CONNECTION_OK) {
- cout << "Failed to connect to the database" << endl;
- exit(-1);
- }
- }
- PGresult* whData::executeSQL(string sql)
- {
- PGresult* res = PQexec(conn, sql.c_str());
- if (!(PQresultStatus(res) == PGRES_COMMAND_OK || PQresultStatus(res) == PGRES_TUPLES_OK)){
- cout << "Failed to execute the command: " << sql << endl;
- cout << PQresultErrorMessage(res) << '\n';
- return NULL;
- }
- return res;
- }
- void whData::closeDB() {
- PQfinish(conn);
- }
- string int_to_string(int i){
- stringstream ss;
- ss << i;
- std::string str = ss.str();
- return str;
- }
- int whData::getStock(int part) {
- string buffer = int_to_string(part);
- //itoa(part,buff,10);
- PGresult* res = executeSQL("SELECT COUNT(*) FROM II.part WHERE type = ('"+ buffer+"')");
- int qty = atoi(PQgetvalue(res,0,1));
- return qty;
- }
- void whData::updateStock() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement