mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 03:26:37 +03:00
Dropped curs_get_last_result function.
The result is read from a pqpath function and put on the async_cursor by a function that also checks for is presence and dismiss it after its usage.
This commit is contained in:
parent
a66de9808f
commit
1edbd16577
|
@ -699,7 +699,8 @@ conn_poll_send(connectionObject *self)
|
|||
|
||||
/* conn_poll_fetch - poll the connection when reading results from the backend
|
||||
*
|
||||
* Assume self->async_cursor is not null: use such cursor to store results.
|
||||
* If self_curs is available, use it to store the result of the last query.
|
||||
* Also unlink it when finished.
|
||||
*/
|
||||
|
||||
PyObject *
|
||||
|
@ -725,10 +726,23 @@ conn_poll_fetch(connectionObject *self)
|
|||
because of asynchronous NOTIFYs that can be sent by the backend
|
||||
even if the user didn't asked for them */
|
||||
|
||||
if (self->async_status == ASYNC_READ)
|
||||
last_result = curs_get_last_result((cursorObject *)self->async_cursor);
|
||||
else
|
||||
if (self->async_status == ASYNC_READ && self->async_cursor) {
|
||||
cursorObject *curs = (cursorObject *)self->async_cursor;
|
||||
IFCLEARPGRES(curs->pgres);
|
||||
curs->pgres = pq_get_last_result(self);
|
||||
|
||||
/* 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. */
|
||||
last_result = pq_fetch(curs) == -1 ? -1 : 0;
|
||||
|
||||
/* We have finished with our async_cursor */
|
||||
Py_XDECREF(self->async_cursor);
|
||||
self->async_cursor = NULL;
|
||||
}
|
||||
else {
|
||||
last_result = 0;
|
||||
}
|
||||
|
||||
if (last_result == 0) {
|
||||
Dprintf("conn_poll_fetch: returning %d", PSYCO_POLL_OK);
|
||||
|
|
|
@ -85,7 +85,6 @@ typedef struct {
|
|||
|
||||
/* C-callable functions in cursor_int.c and cursor_ext.c */
|
||||
HIDDEN void curs_reset(cursorObject *self);
|
||||
HIDDEN int curs_get_last_result(cursorObject *self);
|
||||
|
||||
/* exception-raising macros */
|
||||
#define EXC_IF_CURS_CLOSED(self) \
|
||||
|
|
|
@ -54,45 +54,3 @@ curs_reset(cursorObject *self)
|
|||
self->casts = NULL;
|
||||
Py_XDECREF(tmp);
|
||||
}
|
||||
|
||||
/*
|
||||
* curs_get_last_result
|
||||
*
|
||||
* read all results from the connection, save the last one
|
||||
* returns 0 if all results were read, 1 if there are remaining results, but
|
||||
* their retrieval would block, -1 if there was an error
|
||||
*/
|
||||
|
||||
int
|
||||
curs_get_last_result(cursorObject *self) {
|
||||
PGresult *pgres;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
pthread_mutex_lock(&(self->conn->lock));
|
||||
/* read one result, there can be multiple if the client sent multiple
|
||||
statements */
|
||||
while ((pgres = PQgetResult(self->conn->pgconn)) != NULL) {
|
||||
if (PQisBusy(self->conn->pgconn) == 1) {
|
||||
/* there is another result waiting, need to tell the client to
|
||||
wait more */
|
||||
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;
|
||||
return 1;
|
||||
}
|
||||
Dprintf("curs_get_last_result: got result %p", pgres);
|
||||
IFCLEARPGRES(self->pgres);
|
||||
self->pgres = pgres;
|
||||
}
|
||||
Py_XDECREF(self->conn->async_cursor);
|
||||
self->conn->async_cursor = NULL;
|
||||
pthread_mutex_unlock(&(self->conn->lock));
|
||||
Py_END_ALLOW_THREADS;
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user