summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--psycopg/lobject_int.c5
-rw-r--r--tests/test_lobject.py15
3 files changed, 24 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c913042..d402fa9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-08-08 Federico Di Gregorio <fog@initd.org>
+ * psycopg/lobject_int.c: fixed problem with writing large data using
+ lo_write: apparently the large objects code does not like non-blocking
+ connections.
+
* setup.py: fixed version detection for PostgreSQL rc, as
suggested by Sok Ann Yap.
diff --git a/psycopg/lobject_int.c b/psycopg/lobject_int.c
index cdca5d2..38c1273 100644
--- a/psycopg/lobject_int.c
+++ b/psycopg/lobject_int.c
@@ -201,12 +201,17 @@ lobject_write(lobjectObject *self, const char *buf, size_t len)
PGresult *pgres = NULL;
char *error = NULL;
+ Dprintf("lobject_writing: fd = %d, len = %d",
+ self->fd, len);
+
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&(self->conn->lock));
+ PQsetnonblocking(self->conn->pgconn, 0);
written = lo_write(self->conn->pgconn, self->fd, buf, len);
if (written < 0)
collect_error(self->conn, &error);
+ PQsetnonblocking(self->conn->pgconn, 1);
pthread_mutex_unlock(&(self->conn->lock));
Py_END_ALLOW_THREADS;
diff --git a/tests/test_lobject.py b/tests/test_lobject.py
index 799492c..fc0d852 100644
--- a/tests/test_lobject.py
+++ b/tests/test_lobject.py
@@ -98,6 +98,11 @@ class LargeObjectTests(unittest.TestCase):
lo = self.conn.lobject()
self.assertEqual(lo.write("some data"), len("some data"))
+ def test_write_large(self):
+ lo = self.conn.lobject()
+ data = "data" * 1000000
+ self.assertEqual(lo.write(data), len(data))
+
def test_read(self):
lo = self.conn.lobject()
length = lo.write("some data")
@@ -107,6 +112,16 @@ class LargeObjectTests(unittest.TestCase):
self.assertEqual(lo.read(4), "some")
self.assertEqual(lo.read(), " data")
+ def test_read_large(self):
+ lo = self.conn.lobject()
+ data = "data" * 1000000
+ length = lo.write("some"+data)
+ lo.close()
+
+ lo = self.conn.lobject(lo.oid)
+ self.assertEqual(lo.read(4), "some")
+ self.assertEqual(lo.read(), data)
+
def test_seek_tell(self):
lo = self.conn.lobject()
length = lo.write("some data")