summaryrefslogtreecommitdiff
path: root/psycopg/adapter_binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'psycopg/adapter_binary.c')
-rw-r--r--psycopg/adapter_binary.c7
1 files changed, 5 insertions, 2 deletions
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) {