Skip to content

bpo-43249: Improve scoping #24565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -307,18 +306,18 @@ _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);
if (!colname) {
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");
Expand All @@ -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 */
Expand Down