Search Postgresql Archives

PQisBusy returns true but no more data is received.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello list,

I'm new here, but didn't see the problem in the archives.

Basically, I have an epoll loop that executes the following code when I receive data from postgresql (greatly simplified).

int read_sql (PGconn *conn)
{
  PGnotify *notice;
  PGresult *res;

  if (!PQconsumeInput (conn))
    return -1;

  while (1)
  {
    while ((notice = PQnotifies (conn)))
    {
      handle_notice (notice);
      PQmemfree (notice);
    }

    if (PQisBusy (conn))
      return 0;

    res = PQgetResult (conn);
    if (!res)
      break;

    while ((notice = PQnotifies (conn)))
    {
      handle_notice (notice);
      PQmemfree (notice);
    }

    handle_result (res);
    PQclear (res);
  }

  handle_query_done (conn);
}

(I've not tried to compile this sample code.)
The SQL query in question is a BEGIN followed by a SELECT (sent in the same PQsendQuery()).

The problem is that after two iterations in the loop PQisBusy() returns true, making me exit to the event loop, but no more data is received, so the function will not be called again. If I disable the call to PQisBusy() everything works as expected (PQgetResult() will return NULL on the third iteration). If I move the call to PQisBusy() outside the loop, everything also works good.

Is it safe to move the call to PQisBusy() outside the loop, or is it possible that PQgetResult() will block on a long SELECT in that case? (that would be very bad for me). Or have I misunderstood something about these functions?
--
Pelle Johansson



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux