diff options
| author | Federico Di Gregorio <fog@initd.org> | 2006-09-01 12:36:38 +0000 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2006-09-01 12:36:38 +0000 |
| commit | 9f9af5f907126c625bd400f2feb6c2b50791afa6 (patch) | |
| tree | 10df28877a026b0f51a50ed3e049d5c1ef1ee328 /psycopg/adapter_binary.c | |
| parent | b3fdd80452fc1f5b84a70b3fd2652dbbd1695534 (diff) | |
| download | psycopg2-9f9af5f907126c625bd400f2feb6c2b50791afa6.tar.gz | |
Fixed patch from #119.
Diffstat (limited to 'psycopg/adapter_binary.c')
| -rw-r--r-- | psycopg/adapter_binary.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index dcff6ca..75cfa1c 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -137,10 +137,8 @@ binary_quote(binaryObject *self) 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 */ - else if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) { + if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) { /* escape and build quoted buffer */ PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len); @@ -151,8 +149,14 @@ binary_quote(binaryObject *self) return NULL; } - self->buffer = PyString_FromFormat("'%s'", to); - PQfreemem(to); + if (len > 0) { + self->buffer = PyString_FromFormat("'%s'", to); + PQfreemem(to); + } + else { + self->buffer = PyString_FromString("''"); + PQfreemem(to); + } } /* if the wrapped object is not a string or a buffer, this is an error */ |
