diff options
author | Federico Di Gregorio <fog@initd.org> | 2004-12-14 03:33:03 +0000 |
---|---|---|
committer | Federico Di Gregorio <fog@initd.org> | 2004-12-14 03:33:03 +0000 |
commit | 08a49653425d77219c9af8bfea6e59a7523f63fb (patch) | |
tree | a29181186be474e9e93a6de4a55c35c5d6f01830 | |
parent | 06ef93271a25d5576a71fe7be3c5096a29b90e43 (diff) | |
download | psycopg2-08a49653425d77219c9af8bfea6e59a7523f63fb.tar.gz |
isready/prefetch fix.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | psycopg/cursor.h | 1 | ||||
-rw-r--r-- | psycopg/cursor_type.c | 4 | ||||
-rw-r--r-- | psycopg/pqpath.c | 4 | ||||
-rw-r--r-- | sandbox/test.py | 5 |
5 files changed, 16 insertions, 3 deletions
@@ -1,5 +1,10 @@ 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 types to replect their position in the psycopg._psycopg module. diff --git a/psycopg/cursor.h b/psycopg/cursor.h index a1d6ac3..37b3ebb 100644 --- a/psycopg/cursor.h +++ b/psycopg/cursor.h @@ -40,6 +40,7 @@ typedef struct { int closed:1; /* 1 if the cursor is closed */ 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 columns; /* number of columns fetched from the db */ diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 2051d85..e3b219d 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -511,7 +511,8 @@ _psyco_curs_prefetch(cursorObject *self) } 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"); do { i = pq_fetch(self); @@ -978,6 +979,7 @@ psyco_curs_isready(cursorObject *self, PyObject *args) self->pgres = PQgetResult(self->conn->pgconn); self->conn->async_cursor = NULL; pthread_mutex_unlock(&(self->conn->lock)); + self->needsfetch = 1; Py_INCREF(Py_True); return Py_True; } diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index e7bed66..ea34400 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -669,8 +669,8 @@ pq_fetch(cursorObject *curs) /* even if we fail, we remove any information about the previous query */ 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 get something edible to eat */ if (!curs->pgres) { diff --git a/sandbox/test.py b/sandbox/test.py index def672e..96c8cec 100644 --- a/sandbox/test.py +++ b/sandbox/test.py @@ -23,8 +23,13 @@ def sleep(curs): # FOR READ ONLY;""", async = 1) curs.execute("SELECT now() AS foo", async=1); sleep(curs) +print curs.fetchall() #curs.execute(""" # FETCH FORWARD 1 FROM zz;""", async = 1) curs.execute("SELECT now() AS bar", async=1); +print curs.fetchall() + +curs.execute("SELECT now() AS bar"); sleep(curs) + |