diff options
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/connection.c | 22 | ||||
-rw-r--r-- | Modules/_sqlite/cursor.c | 7 | ||||
-rw-r--r-- | Modules/_sqlite/statement.c | 14 |
3 files changed, 16 insertions, 27 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index e8c28e3..75ccc9a 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -425,16 +425,16 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) sqlite3_result_int64(context, (PY_LONG_LONG)longval); } else if (PyFloat_Check(py_val)) { sqlite3_result_double(context, PyFloat_AsDouble(py_val)); - } else if (PyBuffer_Check(py_val)) { + } else if (PyString_Check(py_val)) { + sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT); + } else if (PyUnicode_Check(py_val)) { + sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT); + } else if (PyObject_CheckBuffer(py_val)) { if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); } else { sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); } - } else if (PyString_Check(py_val)) { - sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT); - } else if (PyUnicode_Check(py_val)) { - sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT); } else { /* TODO: raise error */ } @@ -478,16 +478,8 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_ break; case SQLITE_BLOB: buflen = sqlite3_value_bytes(cur_value); - cur_py_value = PyBuffer_New(buflen); - if (!cur_py_value) { - break; - } - if (PyObject_AsWriteBuffer(cur_py_value, &raw_buffer, &buflen)) { - Py_DECREF(cur_py_value); - cur_py_value = NULL; - break; - } - memcpy(raw_buffer, sqlite3_value_blob(cur_value), buflen); + cur_py_value = PyBytes_FromStringAndSize( + sqlite3_value_blob(cur_value), buflen); break; case SQLITE_NULL: default: diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index c468754..638cbe2 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -380,14 +380,11 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self) } else { /* coltype == SQLITE_BLOB */ nbytes = sqlite3_column_bytes(self->statement->st, i); - buffer = PyBuffer_New(nbytes); + buffer = PyBytes_FromStringAndSize( + sqlite3_column_blob(self->statement->st, i), nbytes); if (!buffer) { break; } - if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &nbytes)) { - break; - } - memcpy(raw_buffer, sqlite3_column_blob(self->statement->st, i), nbytes); converted = buffer; } } diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index b1a4e76..9080c9b 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -102,13 +102,6 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec #endif } else if (PyFloat_Check(parameter)) { rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); - } else if (PyBuffer_Check(parameter)) { - if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { - rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT); - } else { - PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); - rc = -1; - } } else if PyString_Check(parameter) { string = PyString_AsString(parameter); rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); @@ -118,6 +111,13 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); Py_DECREF(stringval); + } else if (PyObject_CheckBuffer(parameter)) { + if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { + rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT); + } else { + PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); + rc = -1; + } } else { rc = -1; } |