~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to psycopg/adapter_binary.c

  • Committer: Federico Di Gregorio
  • Date: 2006-09-01 12:36:38 UTC
  • Revision ID: fog-c044fe82143f514226e3485a39ddab57f1764472
Fixed patch from #119.

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
    int buffer_len;
138
138
    size_t len = 0;
139
139
 
140
 
    if (self->buffer == NULL)
141
 
      self->buffer = PyString_FromString("");
142
140
    /* if we got a plain string or a buffer we escape it and save the buffer */
143
 
    else if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
 
141
    if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
144
142
        /* escape and build quoted buffer */
145
143
        PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
146
144
 
151
149
            return NULL;
152
150
        }
153
151
 
154
 
        self->buffer = PyString_FromFormat("'%s'", to);
155
 
        PQfreemem(to);
 
152
        if (len > 0) {
 
153
            self->buffer = PyString_FromFormat("'%s'", to);
 
154
            PQfreemem(to);
 
155
        }
 
156
        else {
 
157
            self->buffer = PyString_FromString("''");
 
158
            PQfreemem(to);
 
159
        }
156
160
    }
157
161
    
158
162
    /* if the wrapped object is not a string or a buffer, this is an error */