Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-93421: Update sqlite3 cursor.rowcount after SQLITE_DONE#93526

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
8 changes: 8 additions & 0 deletionsLib/test/test_sqlite3/test_dbapi.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,6 +898,14 @@ def test_rowcount_executemany(self):
self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
self.assertEqual(self.cu.rowcount, 3)

@unittest.skipIf(sqlite.sqlite_version_info < (3, 35, 0),
"Requires SQLite 3.35.0 or newer")
def test_rowcount_update_returning(self):
# gh-93421: rowcount is updated correctly for UPDATE...RETURNING queries
self.cu.execute("update test set name='bar' where name='foo' returning 1")
self.assertEqual(self.cu.fetchone()[0], 1)
self.assertEqual(self.cu.rowcount, 1)

def test_total_changes(self):
self.cu.execute("insert into test(name) values ('foo')")
self.cu.execute("insert into test(name) values ('foo')")
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Update :data:`sqlite3.Cursor.rowcount` when a DML statement has run to
completion. This fixes the row count for SQL queries like
``UPDATE ... RETURNING``. Patch by Erlend E. Aasland.
19 changes: 11 additions & 8 deletionsModules/_sqlite/cursor.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -835,10 +835,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
stmt_reset(self->statement);
}

/* reset descriptionand rowcount*/
/* reset description */
Py_INCREF(Py_None);
Py_SETREF(self->description, Py_None);
self->rowcount = 0L;

if (self->statement) {
(void)stmt_reset(self->statement);
Expand DownExpand Up@@ -867,6 +866,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation

stmt_reset(self->statement);
stmt_mark_dirty(self->statement);
self->rowcount = self->statement->is_dml ? 0L : -1L;

/* We start a transaction implicitly before a DML statement.
SELECT is the only exception. See #9924. */
Expand DownExpand Up@@ -944,18 +944,18 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
}
}

if (self->statement->is_dml) {
self->rowcount += (long)sqlite3_changes(self->connection->db);
} else {
self->rowcount= -1L;
}

if (rc == SQLITE_DONE && !multiple) {
if (self->statement->is_dml) {
self->rowcount = (long)sqlite3_changes(self->connection->db);
}
stmt_reset(self->statement);
Py_CLEAR(self->statement);
}

if (multiple) {
if (self->statement->is_dml && rc == SQLITE_DONE) {
self->rowcount += (long)sqlite3_changes(self->connection->db);
}
stmt_reset(self->statement);
}
Py_XDECREF(parameters);
Expand DownExpand Up@@ -1125,6 +1125,9 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
}
int rc = stmt_step(stmt);
if (rc == SQLITE_DONE) {
if (self->statement->is_dml) {
self->rowcount = (long)sqlite3_changes(self->connection->db);
}
(void)stmt_reset(self->statement);
}
else if (rc != SQLITE_ROW) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp