Skip to content

Commit 4585ae8

Browse files
Minor refactoring.
1 parent 1c094a4 commit 4585ae8

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

Modules/_sqlite/cursor.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
252252
return NULL;
253253

254254
for (i = 0; i < numcols; i++) {
255-
if (self->connection->detect_types) {
256-
converter = PyList_GetItem(self->row_cast_map, i);
257-
if (!converter) {
258-
PyErr_Clear();
259-
converter = Py_None;
260-
}
261-
} else {
255+
if (self->connection->detect_types
256+
&& self->row_cast_map != NULL
257+
&& i < PyList_GET_SIZE(self->row_cast_map))
258+
{
259+
converter = PyList_GET_ITEM(self->row_cast_map, i);
260+
}
261+
else {
262262
converter = Py_None;
263263
}
264264

@@ -291,7 +291,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
291291
nbytes = sqlite3_column_bytes(self->statement->st, i);
292292
if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) {
293293
converted = PyUnicode_FromStringAndSize(val_str, nbytes);
294-
if (!converted) {
294+
if (!converted && PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
295295
PyErr_Clear();
296296
colname = sqlite3_column_name(self->statement->st, i);
297297
if (!colname) {

Modules/_sqlite/microprotocols.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,9 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
111111
if (adapted == Py_None) {
112112
Py_DECREF(adapted);
113113
}
114-
else if (adapted) {
114+
else if (adapted || !PyErr_ExceptionMatches(PyExc_TypeError)) {
115115
return adapted;
116116
}
117-
else if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
118-
return NULL;
119-
}
120117
else {
121118
PyErr_Clear();
122119
}
@@ -133,12 +130,9 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
133130
if (adapted == Py_None) {
134131
Py_DECREF(adapted);
135132
}
136-
else if (adapted) {
133+
else if (adapted || !PyErr_ExceptionMatches(PyExc_TypeError)) {
137134
return adapted;
138135
}
139-
else if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
140-
return NULL;
141-
}
142136
else {
143137
PyErr_Clear();
144138
}

0 commit comments

Comments
 (0)