Make pq_clear_async clear the whole pending result and export it

This commit is contained in:
Jan Urbański 2010-03-26 03:39:03 +01:00 committed by Federico Di Gregorio
parent e0d789466a
commit 53748443d8
2 changed files with 12 additions and 5 deletions

View File

@ -283,19 +283,25 @@ pq_resolve_critical(connectionObject *conn, int close)
note that this function does block because it needs to wait for the full note that this function does block because it needs to wait for the full
result sets of the previous query to clear them. result sets of the previous query to clear them.
this function does not call any Py_*_ALLOW_THREADS macros */ this function does not call any Py_*_ALLOW_THREADS macros */
static void void
pq_clear_async(connectionObject *conn) pq_clear_async(connectionObject *conn)
{ {
PGresult *pgres; PGresult *pgres;
do { /* this will get all pending results (if the submitted query consisted of
many parts, i.e. "select 1; select 2", there will be many) and also
finalize asynchronous processing so the connection will be ready to
accept another query */
for (;;) {
pgres = PQgetResult(conn->pgconn); pgres = PQgetResult(conn->pgconn);
Dprintf("pq_clear_async: clearing PGresult at %p", pgres); Dprintf("pq_clear_async: clearing PGresult at %p", pgres);
IFCLEARPGRES(pgres); if (pgres == NULL)
} while (pgres != NULL); break;
CLEARPGRES(pgres);
}
conn->async_cursor = NULL;
} }
/* pg_execute_command_locked - execute a no-result query on a locked connection. /* pg_execute_command_locked - execute a no-result query on a locked connection.

View File

@ -45,6 +45,7 @@ HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
HIDDEN int pq_abort(connectionObject *conn); HIDDEN int pq_abort(connectionObject *conn);
HIDDEN int pq_reset(connectionObject *conn); HIDDEN int pq_reset(connectionObject *conn);
HIDDEN int pq_is_busy(connectionObject *conn); HIDDEN int pq_is_busy(connectionObject *conn);
HIDDEN void pq_clear_async(connectionObject *conn);
HIDDEN void pq_set_critical(connectionObject *conn, const char *msg); HIDDEN void pq_set_critical(connectionObject *conn, const char *msg);