Database header
This commit is contained in:
parent
2b8f34f7af
commit
5269c53dc8
22
Database.cpp
22
Database.cpp
@ -1,4 +1,26 @@
|
||||
#include "Database.hpp"
|
||||
#include "Config.hpp"
|
||||
|
||||
Database::Database(){
|
||||
Config conf("config.txt");
|
||||
std::ostringstream pgsqlConnectingString;
|
||||
|
||||
pgsqlConnectingString
|
||||
<< " host=" << conf.getValue("db_host")
|
||||
<< " dbname=" << conf.getValue("db_name")
|
||||
<< " user=" << conf.getValue("db_user")
|
||||
<< " password=" << conf.getValue("db_pass");
|
||||
|
||||
dbconn = new pqxx::connection(pgsqlConnectingString.str());
|
||||
}
|
||||
|
||||
pqxx::result Database::execute(std::string cmd){
|
||||
pqxx::work w(*dbconn);
|
||||
pqxx::result r(w.exec(cmd));
|
||||
w.commit();
|
||||
return r;
|
||||
}
|
||||
|
||||
void Database::disconnect(){
|
||||
dbconn->close();
|
||||
}
|
||||
|
@ -7,9 +7,14 @@ class Database
|
||||
{
|
||||
private:
|
||||
|
||||
pqxx::connection *dbconn;
|
||||
|
||||
public:
|
||||
Database();
|
||||
|
||||
pqxx::result execute(std::string cmd);
|
||||
|
||||
void disconnect();
|
||||
};
|
||||
|
||||
#endif /* DATABASE_H */
|
||||
|
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -Wall -g
|
||||
LDLIBS= -lpqxx
|
||||
LDLIBS= -lpqxx -lpq
|
||||
SOURCES= $(wildcard *.cpp)
|
||||
|
||||
all: main
|
||||
|
Loading…
Reference in New Issue
Block a user