diff options
| -rw-r--r-- | ChangeLog | 3 | ||||
| -rw-r--r-- | psycopg/adapter_binary.c | 7 | ||||
| -rw-r--r-- | tests/types_basic.py | 3 |
3 files changed, 11 insertions, 2 deletions
@@ -1,5 +1,8 @@ 2006-09-01 Federico Di Gregorio <fog@initd.org> + * psycopg/adapter_binary.c: applied patch from jdahlin (#119) + to fix the segfault on empty binary buffers. + * psycopg/connection_type.c: added .status attribute to expose the internal status. diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index e380b2b..dcff6ca 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -136,11 +136,14 @@ binary_quote(binaryObject *self) const char *buffer; int buffer_len; size_t len = 0; - + + if (self->buffer == NULL) + self->buffer = PyString_FromString(""); /* if we got a plain string or a buffer we escape it and save the buffer */ - if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) { + else if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) { /* escape and build quoted buffer */ PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len); + to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len, self->conn ? ((connectionObject*)self->conn)->pgconn : NULL); if (to == NULL) { diff --git a/tests/types_basic.py b/tests/types_basic.py index 3abaf92..8a867df 100644 --- a/tests/types_basic.py +++ b/tests/types_basic.py @@ -63,6 +63,9 @@ class TypesBasicTests(TestCase): r = str(self.execute("SELECT %s::bytea AS foo", (b,))) self.failUnless(r == s, "wrong binary quoting") + b = psycopg2.Binary('') + self.assertEqual(str(b), '') + def testArray(self): s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],)) self.failUnless(s == [[1,2],[3,4]], "wrong array quoting " + str(s)) |
