Skip to content

Commit 38afeb1

Browse files
author
Erlend Egeberg Aasland
authored
bpo-46249: Move set lastrowid out of the sqlite3 query loop (GH-30489)
1 parent 82c5322 commit 38afeb1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Modules/_sqlite/cursor.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
465465
int rc;
466466
int numcols;
467467
PyObject* column_name;
468-
sqlite_int64 lastrowid;
469468

470469
if (!check_cursor(self)) {
471470
goto error;
@@ -630,16 +629,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
630629
self->rowcount= -1L;
631630
}
632631

633-
if (!multiple) {
634-
Py_BEGIN_ALLOW_THREADS
635-
lastrowid = sqlite3_last_insert_rowid(self->connection->db);
636-
Py_END_ALLOW_THREADS
637-
Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid));
638-
if (self->lastrowid == NULL) {
639-
goto error;
640-
}
641-
}
642-
643632
if (rc == SQLITE_DONE && !multiple) {
644633
pysqlite_statement_reset(self->statement);
645634
Py_CLEAR(self->statement);
@@ -651,6 +640,17 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
651640
Py_XDECREF(parameters);
652641
}
653642

643+
if (!multiple) {
644+
sqlite_int64 lastrowid;
645+
646+
Py_BEGIN_ALLOW_THREADS
647+
lastrowid = sqlite3_last_insert_rowid(self->connection->db);
648+
Py_END_ALLOW_THREADS
649+
650+
Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid));
651+
// Fall through on error.
652+
}
653+
654654
error:
655655
Py_XDECREF(parameters);
656656
Py_XDECREF(parameters_iter);

0 commit comments

Comments
 (0)