diff options
| author | Jan UrbaĆski <wulczer@wulczer.org> | 2010-04-11 20:25:17 +0200 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-20 23:01:01 +0100 |
| commit | c4ebc0f702dfc3bae92ff3ffc01b9d6ed5d2fbde (patch) | |
| tree | 46d8cd7c5875f77c574b63504525b70ec1f2aa92 /psycopg/cursor_int.c | |
| parent | 249b3ef88fcb57cddf9992175d60c782ee663b25 (diff) | |
| download | psycopg2-c4ebc0f702dfc3bae92ff3ffc01b9d6ed5d2fbde.tar.gz | |
Handle errors in asynchronous queries.
Do it by keeping the reference to the last PGresult in the cursor and
calling pq_fetch() before ending the asynchronous execution. This
takes care of handling the possible error state of the PGresult and
also allows the removal of the needsfetch flag, since now after
execution ends the results are already fetched and parsed.
Diffstat (limited to 'psycopg/cursor_int.c')
| -rw-r--r-- | psycopg/cursor_int.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/psycopg/cursor_int.c b/psycopg/cursor_int.c index 32f3b72..1069aae 100644 --- a/psycopg/cursor_int.c +++ b/psycopg/cursor_int.c @@ -67,7 +67,6 @@ int curs_get_last_result(cursorObject *self) { PGresult *pgres; - IFCLEARPGRES(self->pgres); Py_BEGIN_ALLOW_THREADS; pthread_mutex_lock(&(self->conn->lock)); /* read one result, there can be multiple if the client sent multiple @@ -76,7 +75,8 @@ curs_get_last_result(cursorObject *self) { if (PQisBusy(self->conn->pgconn) == 1) { /* there is another result waiting, need to tell the client to wait more */ - Dprintf("curs_get_last_result: gut result, but more are pending"); + Dprintf("curs_get_last_result: got result, but more are pending"); + IFCLEARPGRES(self->pgres); self->pgres = pgres; pthread_mutex_unlock(&(self->conn->lock)); Py_BLOCK_THREADS; @@ -90,8 +90,10 @@ curs_get_last_result(cursorObject *self) { self->conn->async_cursor = NULL; pthread_mutex_unlock(&(self->conn->lock)); Py_END_ALLOW_THREADS; - self->needsfetch = 1; - return 0; + /* fetch the tuples (if there are any) and build the result. We don't care + if pq_fetch return 0 or 1, but if there was an error, we want to signal + it to the caller. */ + return pq_fetch(self) == -1 ? -1 : 0; } /* curs_poll_send - handle cursor polling when flushing output */ |
