mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
isready/prefetch fix.
This commit is contained in:
parent
06ef93271a
commit
08a4965342
|
@ -1,5 +1,10 @@
|
||||||
2004-12-14 Federico Di Gregorio <fog@debian.org>
|
2004-12-14 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
|
* psycopg/cursor_type.c (_psyco_curs_prefetch): fixed bug in
|
||||||
|
interaction between the .isready() method and
|
||||||
|
_psyco_curs_prefetch: isready now store away the pgres but leave
|
||||||
|
prefetch do its work.
|
||||||
|
|
||||||
* psycopg/*.c: changed the names of most of the psycopg's built-in
|
* psycopg/*.c: changed the names of most of the psycopg's built-in
|
||||||
types to replect their position in the psycopg._psycopg module.
|
types to replect their position in the psycopg._psycopg module.
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ typedef struct {
|
||||||
|
|
||||||
int closed:1; /* 1 if the cursor is closed */
|
int closed:1; /* 1 if the cursor is closed */
|
||||||
int notuples:1; /* 1 if the command was not a SELECT query */
|
int notuples:1; /* 1 if the command was not a SELECT query */
|
||||||
|
int needsfetch:1; /* 1 if a call to pq_fetch is pending */
|
||||||
|
|
||||||
long int rowcount; /* number of rows affected by last execute */
|
long int rowcount; /* number of rows affected by last execute */
|
||||||
long int columns; /* number of columns fetched from the db */
|
long int columns; /* number of columns fetched from the db */
|
||||||
|
|
|
@ -511,7 +511,8 @@ _psyco_curs_prefetch(cursorObject *self)
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&(self->conn->lock));
|
pthread_mutex_unlock(&(self->conn->lock));
|
||||||
|
|
||||||
if (self->pgres == NULL) {
|
if (self->pgres == NULL || self->needsfetch) {
|
||||||
|
self->needsfetch = 0;
|
||||||
Dprintf("_psyco_curs_prefetch: trying to fetch data");
|
Dprintf("_psyco_curs_prefetch: trying to fetch data");
|
||||||
do {
|
do {
|
||||||
i = pq_fetch(self);
|
i = pq_fetch(self);
|
||||||
|
@ -978,6 +979,7 @@ psyco_curs_isready(cursorObject *self, PyObject *args)
|
||||||
self->pgres = PQgetResult(self->conn->pgconn);
|
self->pgres = PQgetResult(self->conn->pgconn);
|
||||||
self->conn->async_cursor = NULL;
|
self->conn->async_cursor = NULL;
|
||||||
pthread_mutex_unlock(&(self->conn->lock));
|
pthread_mutex_unlock(&(self->conn->lock));
|
||||||
|
self->needsfetch = 1;
|
||||||
Py_INCREF(Py_True);
|
Py_INCREF(Py_True);
|
||||||
return Py_True;
|
return Py_True;
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,8 +669,8 @@ pq_fetch(cursorObject *curs)
|
||||||
|
|
||||||
/* even if we fail, we remove any information about the previous query */
|
/* even if we fail, we remove any information about the previous query */
|
||||||
curs_reset(curs);
|
curs_reset(curs);
|
||||||
|
|
||||||
/* we check the result from the previous execute; if the result is not
|
/* we check the result from the previous execute; if the result is not
|
||||||
already there, we need to consume some input and go to sleep until we
|
already there, we need to consume some input and go to sleep until we
|
||||||
get something edible to eat */
|
get something edible to eat */
|
||||||
if (!curs->pgres) {
|
if (!curs->pgres) {
|
||||||
|
|
|
@ -23,8 +23,13 @@ def sleep(curs):
|
||||||
# FOR READ ONLY;""", async = 1)
|
# FOR READ ONLY;""", async = 1)
|
||||||
curs.execute("SELECT now() AS foo", async=1);
|
curs.execute("SELECT now() AS foo", async=1);
|
||||||
sleep(curs)
|
sleep(curs)
|
||||||
|
print curs.fetchall()
|
||||||
|
|
||||||
#curs.execute("""
|
#curs.execute("""
|
||||||
# FETCH FORWARD 1 FROM zz;""", async = 1)
|
# FETCH FORWARD 1 FROM zz;""", async = 1)
|
||||||
curs.execute("SELECT now() AS bar", async=1);
|
curs.execute("SELECT now() AS bar", async=1);
|
||||||
|
print curs.fetchall()
|
||||||
|
|
||||||
|
curs.execute("SELECT now() AS bar");
|
||||||
sleep(curs)
|
sleep(curs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user