diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:08:45 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:08:45 +0000 |
commit | 735d50c782b436d6807fd15e1b37e2231ce3e146 (patch) | |
tree | 866d86adf5660c1f9a218eae6d99eb74b024ed32 | |
parent | a9dc1b83ad96c336f2ff208ed01b591fb08081a0 (diff) | |
download | psycopg2-735d50c782b436d6807fd15e1b37e2231ce3e146.tar.gz |
Check if the object wrapped in binary is not None before trying the other types
Otherwise it seems we clobber some result with NULL.
-rw-r--r-- | psycopg/adapter_binary.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index da3bec6..b08c144 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -65,6 +65,13 @@ binary_quote(binaryObject *self) int got_view = 0; #endif + /* Allow Binary(None) to work */ + if (self->wrapped == Py_None) { + Py_INCREF(psyco_null); + rv = psyco_null; + goto exit; + } + /* if we got a plain string or a buffer we escape it and save the buffer */ #if HAS_MEMORYVIEW @@ -93,7 +100,7 @@ binary_quote(binaryObject *self) /* escape and build quoted buffer */ - to = (char *)binary_escape((unsigned char*)buffer, (size_t) buffer_len, + to = (char *)binary_escape((unsigned char*)buffer, (size_t)buffer_len, &len, self->conn ? ((connectionObject*)self->conn)->pgconn : NULL); if (to == NULL) { PyErr_NoMemory(); @@ -113,12 +120,6 @@ exit: if (got_view) { PyBuffer_Release(&view); } #endif - /* Allow Binary(None) to work */ - if (self->wrapped == Py_None) { - Py_INCREF(psyco_null); - rv = psyco_null; - } - /* if the wrapped object is not bytes or a buffer, this is an error */ if (!rv && !PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "can't escape %s to binary", |