6#if __has_include(<libpq-fe.h>)
9# include <postgresql/libpq-fe.h>
17 Connection(std::string user, std::string pass, std::string host,
int port, std::string dbname) {
18 int libpq_ver = PQlibVersion();
22 ss <<
"user=" << user <<
" password=" << pass <<
" host=" << host <<
" dbname=" << dbname <<
" port=" << port;
24 conn = PQconnectdb(ss.str().c_str());
26 if(PQstatus(
conn) != CONNECTION_OK)
27 throw std::runtime_error(PQerrorMessage(
conn));
42 PGresult* res = PQexec(
conn, query.c_str());
44 if(PQresultStatus(res) != PGRES_COMMAND_OK)
45 throw std::runtime_error(PQerrorMessage(
conn));
Connection(std::string user, std::string pass, std::string host, int port, std::string dbname)
void Execute(std::string query)