Het maken van de DB connectie gebeurd nu asynchroon.

This commit is contained in:
Eelke Klein 2016-12-27 15:41:11 +01:00
parent 27abce5a11
commit 3a8cc3d7f0
5 changed files with 207 additions and 18 deletions

View file

@ -114,6 +114,26 @@ bool Connection::connect(const char *params)
return result;
}
bool Connection::connectStart(const char* params)
{
conn = PQconnectStart(params);
return conn != nullptr;
}
PostgresPollingStatusType Connection::connectPoll()
{
return PQconnectPoll(conn);
}
ConnStatusType Connection::status()
{
return PQstatus(conn);
}
int Connection::socket()
{
return PQsocket(conn);
}
std::string Connection::getErrorMessage() const
{
@ -127,9 +147,9 @@ std::string Connection::getErrorMessage() const
return result;
}
Result Connection::Query(const char * query)
Result Connection::query(const char * command)
{
PGresult *result = PQexec(conn, query);
PGresult *result = PQexec(conn, command);
if (result) {
return Result(result);
}
@ -137,3 +157,23 @@ Result Connection::Query(const char * query)
throw std::runtime_error("Failed to allocate result object");
}
}
bool Connection::sendQuery(const char *query)
{
int res = PQsendQuery(conn, query);
return res == 1;
}
std::unique_ptr<Result> Connection::getResult()
{
PGresult *r = PQgetResult(conn);
if (r) {
return std::make_unique<Result>(r);
}
else {
return nullptr;
}
}