-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix RecordsAffected incorrectly accumulating counts from DDL statements #37397
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: cincuranet <[email protected]>
Co-authored-by: cincuranet <[email protected]>
Co-authored-by: cincuranet <[email protected]>
…lit test Co-authored-by: cincuranet <[email protected]>
…reation Co-authored-by: cincuranet <[email protected]>
Co-authored-by: cincuranet <[email protected]>
Co-authored-by: cincuranet <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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.