summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/cursor.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-09 23:37:01 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-09 23:37:01 (GMT)
commit83857e3bf316cf09f06dd46513fe08773ed0f51b (patch)
tree61a9c072ea6ff5efa370aa157ba181a5f3d06256 /Modules/_sqlite/cursor.c
parent63eac1592700e550d7a8e9b5ef1f77cadac9a020 (diff)
downloadcpython-83857e3bf316cf09f06dd46513fe08773ed0f51b.zip
cpython-83857e3bf316cf09f06dd46513fe08773ed0f51b.tar.gz
cpython-83857e3bf316cf09f06dd46513fe08773ed0f51b.tar.bz2
Use AsCharBuffer to get C strings out of Python strings.
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r--Modules/_sqlite/cursor.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index ca15eed..cbb030e 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -409,8 +409,8 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
{
PyObject* operation;
- PyObject* operation_bytestr = NULL;
- char* operation_cstr;
+ const char* operation_cstr;
+ Py_ssize_t operation_len;
PyObject* parameters_list = NULL;
PyObject* parameters_iter = NULL;
PyObject* parameters = NULL;
@@ -495,16 +495,8 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
rc = pysqlite_statement_reset(self->statement);
}
- if (PyString_Check(operation)) {
- operation_cstr = PyString_AsString(operation);
- } else {
- operation_bytestr = PyUnicode_AsUTF8String(operation);
- if (!operation_bytestr) {
- goto error;
- }
-
- operation_cstr = PyString_AsString(operation_bytestr);
- }
+ if (PyObject_AsCharBuffer(operation, &operation_cstr, &operation_len) < 0)
+ goto error;
/* reset description and rowcount */
Py_DECREF(self->description);
@@ -714,7 +706,6 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
}
error:
- Py_XDECREF(operation_bytestr);
Py_XDECREF(parameters);
Py_XDECREF(parameters_iter);
Py_XDECREF(parameters_list);