Fix RecordsAffected incorrectly accumulating counts from DDL statements#37397
Merged
cincuranet merged 9 commits intomainfrom Jan 6, 2026
Merged
Fix RecordsAffected incorrectly accumulating counts from DDL statements#37397cincuranet merged 9 commits intomainfrom
cincuranet merged 9 commits intomainfrom
Conversation
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix incorrect RecordsAffected calculation in Microsoft.Data.Sqlite
Fix RecordsAffected incorrectly accumulating counts from DDL statements
Dec 18, 2025
cincuranet
requested changes
Dec 18, 2025
…lit test Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
cincuranet
requested changes
Dec 19, 2025
…reation Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
cincuranet
approved these changes
Dec 19, 2025
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
cincuranet
requested changes
Dec 19, 2025
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where RecordsAffected incorrectly accumulated counts from DDL statements in Microsoft.Data.Sqlite. The root cause was that sqlite3_changes() persists its value across DDL statements, returning the count from the most recent INSERT/UPDATE/DELETE even when called after a DDL statement like CREATE or DROP.
Key Changes
- Modified
SqliteDataReader.NextResult()to usesqlite3_total_changes()before and after statement execution to calculate the actual delta, ensuring DDL statements don't add stale counts - Added comprehensive tests to verify DDL statements don't affect
RecordsAffected - Updated existing test expectation for CREATE INDEX to correctly expect 0 records affected
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs | Implemented fix using sqlite3_total_changes() delta to detect actual changes and sqlite3_changes() to get accurate row counts excluding trigger changes |
| test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs | Added two comprehensive tests verifying DDL statements (DROP, CREATE) don't incorrectly affect RecordsAffected |
| test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs | Corrected expectation for CREATE INDEX from 1 to 0, since DDL statements should not report records affected |
e39db3a to
3c103a6
Compare
cincuranet
approved these changes
Jan 5, 2026
AndriySvyryd
approved these changes
Jan 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
handletoconnectionHandleint changestovar changesusingblocks and assert from withinusing (var connection = ...)blocks for consistencyconnection.ExecuteNonQuery("CREATE TABLE foo...")lineDROP TABLE footoDROP TABLE IF EXISTS footo avoid errorDROP TABLE IF EXISTS foostatement from testOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.