diff options
-rw-r--r-- | Modules/_sqlite/cursor.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 63176b8..d1578ad 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -249,7 +249,6 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) PyObject* converter; PyObject* converted; Py_ssize_t nbytes; - const char* val_str; char buf[200]; const char* colname; PyObject* error_msg; @@ -285,12 +284,12 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) * See https://sqlite.org/c3ref/column_blob.html for details. */ if (converter != Py_None) { - val_str = (const char*)sqlite3_column_blob(self->statement->st, i); + const char *blob = (const char*)sqlite3_column_blob(self->statement->st, i); nbytes = sqlite3_column_bytes(self->statement->st, i); - if (!val_str) { + if (!blob) { converted = Py_NewRef(Py_None); } else { - item = PyBytes_FromStringAndSize(val_str, nbytes); + item = PyBytes_FromStringAndSize(blob, nbytes); if (!item) goto error; converted = PyObject_CallOneArg(converter, item); @@ -307,10 +306,10 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) } else if (coltype == SQLITE_FLOAT) { converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i)); } else if (coltype == SQLITE_TEXT) { - val_str = (const char*)sqlite3_column_text(self->statement->st, i); + const char *text = (const char*)sqlite3_column_text(self->statement->st, i); nbytes = sqlite3_column_bytes(self->statement->st, i); if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) { - converted = PyUnicode_FromStringAndSize(val_str, nbytes); + converted = PyUnicode_FromStringAndSize(text, nbytes); if (!converted && PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) { PyErr_Clear(); colname = sqlite3_column_name(self->statement->st, i); @@ -318,7 +317,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) colname = "<unknown column name>"; } PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'", - colname , val_str); + colname , text); error_msg = PyUnicode_Decode(buf, strlen(buf), "ascii", "replace"); if (!error_msg) { PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8"); @@ -328,11 +327,11 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) } } } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) { - converted = PyBytes_FromStringAndSize(val_str, nbytes); + converted = PyBytes_FromStringAndSize(text, nbytes); } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) { - converted = PyByteArray_FromStringAndSize(val_str, nbytes); + converted = PyByteArray_FromStringAndSize(text, nbytes); } else { - converted = PyObject_CallFunction(self->connection->text_factory, "y#", val_str, nbytes); + converted = PyObject_CallFunction(self->connection->text_factory, "y#", text, nbytes); } } else { /* coltype == SQLITE_BLOB */ |