summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--psycopg/cursor_type.c11
-rw-r--r--psycopg2.mdp2
-rw-r--r--sandbox/test_isready_connection_closed.py31
4 files changed, 46 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e1b3559..487943a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-10 Federico Di Gregorio <fog@initd.org>
+
+ * psycopg/cursor_type.c: cursor.isready() now raise an exception
+ when the libpq PQconsumeInput() call fails.
+
2008-12-04 Federico Di Gregorio <fog@initd.org>
* psycopg/lobject_type.c: fixed memory leak. The patch was kindly
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c
index 3749467..a85e030 100644
--- a/psycopg/cursor_type.c
+++ b/psycopg/cursor_type.c
@@ -1479,17 +1479,24 @@ psyco_curs_fileno(cursorObject *self, PyObject *args)
static PyObject *
psyco_curs_isready(cursorObject *self, PyObject *args)
{
+ int res;
+
if (!PyArg_ParseTuple(args, "")) return NULL;
EXC_IF_CURS_CLOSED(self);
/* pq_is_busy does its own locking, we don't need anything special but if
the cursor is ready we need to fetch the result and free the connection
- for the next query. */
+ for the next query. if -1 is returned we raise an exception. */
- if (pq_is_busy(self->conn)) {
+ res = pq_is_busy(self->conn);
+
+ if (res == 1) {
Py_INCREF(Py_False);
return Py_False;
}
+ else if (res == -1) {
+ return NULL;
+ }
else {
IFCLEARPGRES(self->pgres);
Py_BEGIN_ALLOW_THREADS;
diff --git a/psycopg2.mdp b/psycopg2.mdp
index 99b8ace..f3dff0f 100644
--- a/psycopg2.mdp
+++ b/psycopg2.mdp
@@ -137,11 +137,11 @@
<File name="tests/test_dates.py" subtype="Code" buildaction="Nothing" />
<File name="tests/test_lobject.py" subtype="Code" buildaction="Nothing" />
<File name="tests/test_quote.py" subtype="Code" buildaction="Nothing" />
- <File name="psycopg/cursor_type.c.~1~" subtype="Code" buildaction="Nothing" />
<File name="psycopg/lobject.h" subtype="Code" buildaction="Nothing" />
<File name="psycopg/lobject_int.c" subtype="Code" buildaction="Compile" />
<File name="psycopg/lobject_type.c" subtype="Code" buildaction="Compile" />
<File name="psycopg/typecast_basic.c.old" subtype="Code" buildaction="Nothing" />
+ <File name="sandbox/test_isready_connection_closed.py" subtype="Code" buildaction="Nothing" />
</Contents>
<compiler ctype="GccCompiler" />
<MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />
diff --git a/sandbox/test_isready_connection_closed.py b/sandbox/test_isready_connection_closed.py
new file mode 100644
index 0000000..25377ac
--- /dev/null
+++ b/sandbox/test_isready_connection_closed.py
@@ -0,0 +1,31 @@
+import gc
+import sys
+import os
+import signal
+import warnings
+import psycopg2
+
+print "Testing psycopg2 version %s" % psycopg2.__version__
+
+dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test')
+conn = psycopg2.connect("dbname=%s" % dbname)
+curs = conn.cursor()
+curs.isready()
+
+print "Now restart the test postgresql server to drop all connections, press enter when done."
+raw_input()
+
+try:
+ curs.isready() # No need to test return value
+ curs.isready()
+except:
+ print "Test passed"
+ sys.exit(0)
+
+if curs.isready():
+ print "Warning: looks like the connection didn't get killed. This test is probably in-effective"
+ print "Test inconclusive"
+ sys.exit(1)
+
+gc.collect() # used to error here
+print "Test Passed"