diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2022-01-22 09:40:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-22 09:40:22 (GMT) |
commit | 38afeb1a336f0451c0db86df567ef726f49f6438 (patch) | |
tree | df491444006cd3fef3b1767e2f72374c5bb1c228 /Modules | |
parent | 82c53229e18f5853c82cb8ab6b9af1925a0e9e58 (diff) | |
download | cpython-38afeb1a336f0451c0db86df567ef726f49f6438.zip cpython-38afeb1a336f0451c0db86df567ef726f49f6438.tar.gz cpython-38afeb1a336f0451c0db86df567ef726f49f6438.tar.bz2 |
bpo-46249: Move set lastrowid out of the sqlite3 query loop (GH-30489)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/cursor.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 2729a85..4700afb 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -465,7 +465,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation int rc; int numcols; PyObject* column_name; - sqlite_int64 lastrowid; if (!check_cursor(self)) { goto error; @@ -630,16 +629,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation self->rowcount= -1L; } - if (!multiple) { - Py_BEGIN_ALLOW_THREADS - lastrowid = sqlite3_last_insert_rowid(self->connection->db); - Py_END_ALLOW_THREADS - Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid)); - if (self->lastrowid == NULL) { - goto error; - } - } - if (rc == SQLITE_DONE && !multiple) { pysqlite_statement_reset(self->statement); Py_CLEAR(self->statement); @@ -651,6 +640,17 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation Py_XDECREF(parameters); } + if (!multiple) { + sqlite_int64 lastrowid; + + Py_BEGIN_ALLOW_THREADS + lastrowid = sqlite3_last_insert_rowid(self->connection->db); + Py_END_ALLOW_THREADS + + Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid)); + // Fall through on error. + } + error: Py_XDECREF(parameters); Py_XDECREF(parameters_iter); |