Skip to content

gh-163106: Add sqlite3.Connection.changes - #163108

Open
csm10495 wants to merge 7 commits into
python:mainfrom
csm10495:gh-163106-sqlite3-connection-changes
Open

csm10495 wants to merge 7 commits into
python:mainfrom
csm10495:gh-163106-sqlite3-connection-changes

Conversation

@csm10495

@csm10495 csm10495 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Expose sqlite3_changes64() (falling back to sqlite3_changes() on SQLite older than 3.37) as a read-only Connection.changes attribute, returning the number of rows modified, inserted, or deleted by the most recently completed INSERT, UPDATE, or DELETE statement.

As a one-off to test calling the 64 version locally, I created a database with over 2 billion rows (to pass the 32 bit limit) then did DELETE FROM data to delete the all rows. After that I checked that connection.changes didn't rollover (so the 64 bit version was called). I can't really think of a way to do this test in a CI environment since it used about 20 gigs of RAM and took almost 3 minutes to run once.

I figure a one off, with the code review here should be good enough (instead of adding that test with bigmem, etc.)

Expose sqlite3_changes64() (falling back to sqlite3_changes() on SQLite
older than 3.37) as a read-only Connection.changes attribute, returning
the number of rows modified, inserted, or deleted by the most recently
completed INSERT, UPDATE, or DELETE statement.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@python-cla-bot

python-cla-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

read-the-docs-community Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

📖 3 files modified


Preview · build overview · cpython-previews · built Dec. 4, 2026, 4:01 a.m. UTC

Comment thread Modules/_sqlite/connection.c Resolved
@picnixz

picnixz commented Dec 3, 2026

Copy link
Copy Markdown
Member

I can't really think of a way to do this test in a CI environment since it used about 20 gigs of RAM and took almost 3 minutes to run once.

This is a bigmem test then

@csm10495

csm10495 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

I can't really think of a way to do this test in a CI environment since it used about 20 gigs of RAM and took almost 3 minutes to run once.

This is a bigmem test then

Think it's worth having in the code base just to check that the 64 version ran?

@picnixz

picnixz commented Dec 4, 2026

Copy link
Copy Markdown
Member

Mmh, no

@csm10495
csm10495 requested review from a team, corona10, emmatyping and itamaro as code owners December 4, 2026 03:49
@csm10495
csm10495 requested a review from picnixz December 4, 2026 04:23
@csm10495

csm10495 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@picnixz updated to use configure instead of inline figuring out availability of the 64 version. Please check again when you get a chance.

@efanntyo

efanntyo commented Dec 4, 2026

Copy link
Copy Markdown

A small semantic regression test, independent of the 32/64-bit availability discussion, could distinguish changes from total_changes when triggers write additional rows.

For example, create source(id, value) with two rows and an AFTER UPDATE trigger that inserts one audit row per updated source row. After UPDATE source SET value = 1, expect connection.changes == 2 while the total_changes delta is 4 and audit has 2 rows. Then an UPDATE with no matching id should reset changes to 0. This covers both the direct-versus-trigger boundary and the zero-match behavior described in the new docs.

I verified those expected values using SELECT changes() on Python 3.12.16 / SQLite 3.53.1, and inspected the getter/tests at 61d1245. SQLite documents that auxiliary trigger changes are excluded: https://www.sqlite.org/c3ref/changes.html. The new Python attribute itself was not executed here, so this is a proposed low-cost contract test, not a PR-build result or a substitute for the 64-bit boundary check. AI assistance was used for the original probe and this write-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants