Skip to content

Add support for fetching sqlite3_changes (count) via Connection.changes #163106

Backlog

Description

@csm10495

Feature or enhancement

Add support for fetching the number of rows modified via https://www.sqlite.org/c3ref/changes.html. Example usage:

import sqlite3

conn = sqlite3.connect("example.db")
cursor = conn.cursor()

# Create a table
cursor.execute("""
    CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY,
        name TEXT
    )
""")

# Insert records
cursor.execute("INSERT INTO users (name) VALUES (?)", ("Alice",))

print("Changes:", conn.changes)           # 1
print("Total changes:", conn.total_changes)  # 1

# Insert another record
cursor.execute("INSERT INTO users (name) VALUES (?)", ("Bob",))

print("Changes:", conn.changes)           # 1
print("Total changes:", conn.total_changes)  # 2

# Update a record
cursor.execute(
    "UPDATE users SET name = ? WHERE id = ?",
    ("Charlie", 1)
)

print("Changes:", conn.changes)           # 1
print("Total changes:", conn.total_changes)  # 3

# Delete a record
cursor.execute("DELETE FROM users WHERE id = ?", (2,))

print("Changes:", conn.changes)           # 1
print("Total changes:", conn.total_changes)  # 4

conn.close()

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/sqlite3-module-implement-connection-changes/110423

Linked PRs

Activity

  1. added
    type-feature
    on Dec 3, 2026
  2. added a commit that references this issue on Dec 3, 2026
  3. added a commit that references this issue on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulestopic-sqlite3type-feature

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions