Skip to content

Commit

Permalink
bpo-43083: Fix error handling in _sqlite3 (GH-24395)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9073180)

Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
miss-islington and serhiy-storchaka authored Jan 31, 2021
1 parent 995a6c0 commit 8a833a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,11 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
(callable != Py_None) ? callable : NULL,
(callable != Py_None) ? pysqlite_collation_callback : NULL);
if (rc != SQLITE_OK) {
PyDict_DelItem(self->collations, uppercase_name);
if (callable != Py_None) {
if (PyDict_DelItem(self->collations, uppercase_name) < 0) {
PyErr_Clear();
}
}
_pysqlite_seterror(self->db, NULL);
goto finally;
}
Expand Down
20 changes: 14 additions & 6 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,13 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
}

if (!multiple) {
Py_DECREF(self->lastrowid);
Py_BEGIN_ALLOW_THREADS
lastrowid = sqlite3_last_insert_rowid(self->connection->db);
Py_END_ALLOW_THREADS
self->lastrowid = PyLong_FromLongLong(lastrowid);
Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid));
if (self->lastrowid == NULL) {
goto error;
}
}

if (rc == SQLITE_ROW) {
Expand Down Expand Up @@ -802,8 +804,11 @@ PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args, PyObj
}

while ((row = pysqlite_cursor_iternext(self))) {
PyList_Append(list, row);
Py_XDECREF(row);
if (PyList_Append(list, row) < 0) {
Py_DECREF(row);
break;
}
Py_DECREF(row);

if (++counter == maxrows) {
break;
Expand All @@ -829,8 +834,11 @@ PyObject* pysqlite_cursor_fetchall(pysqlite_Cursor* self, PyObject* args)
}

while ((row = pysqlite_cursor_iternext(self))) {
PyList_Append(list, row);
Py_XDECREF(row);
if (PyList_Append(list, row) < 0) {
Py_DECREF(row);
break;
}
Py_DECREF(row);
}

if (PyErr_Occurred()) {
Expand Down

0 comments on commit 8a833a6

Please sign in to comment.