Merge pull request #16 from an-tao/debug

Fix a bug of PostgreSQL connections.
This commit is contained in:
an-tao 2018-12-11 15:23:52 +08:00 committed by GitHub
commit 2989168612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 34 deletions

View File

@ -144,9 +144,10 @@ void PgConnection::execSql(const std::string &sql,
_idleCb = idleCb; _idleCb = idleCb;
_isWorking = true; _isWorking = true;
_exceptCb = exceptCallback; _exceptCb = exceptCallback;
auto thisPtr = shared_from_this();
_loop->runInLoop([thisPtr, sql, paraNum, parameters, length, format]() {
if (PQsendQueryParams( if (PQsendQueryParams(
_connPtr.get(), thisPtr->_connPtr.get(),
sql.c_str(), sql.c_str(),
paraNum, paraNum,
NULL, NULL,
@ -155,35 +156,14 @@ void PgConnection::execSql(const std::string &sql,
format.data(), format.data(),
0) == 0) 0) == 0)
{ {
LOG_ERROR << "send query error: " << PQerrorMessage(_connPtr.get()); LOG_ERROR << "send query error: " << PQerrorMessage(thisPtr->_connPtr.get());
// connection broken! will be handled in handleRead()
// _loop->queueInLoop([=]() {
// try
// {
// throw InternalError(PQerrorMessage(_connPtr.get()));
// }
// catch (...)
// {
// _isWorking = false;
// _exceptCb(std::current_exception());
// _exceptCb = decltype(_exceptCb)();
// if (_idleCb)
// {
// _idleCb();
// _idleCb = decltype(_idleCb)();
// }
// }
// });
// return;
} }
auto thisPtr = shared_from_this();
_loop->runInLoop([=]() {
thisPtr->pgPoll(); thisPtr->pgPoll();
}); });
} }
void PgConnection::handleRead() void PgConnection::handleRead()
{ {
_loop->assertInLoopThread();
std::shared_ptr<PGresult> res; std::shared_ptr<PGresult> res;
if (!PQconsumeInput(_connPtr.get())) if (!PQconsumeInput(_connPtr.get()))