Repository navigation
[Vsintegration] XDatabase: register the collation before the VACUUM - #2132
Merged
RobertvanderHulst merged 1 commit intoOct 28, 2026
Merged
Conversation
…he VACUUM The VACUUM rebuilds the NOCASE indexes with the collation that is registered on the connection at that moment. SetCollation() ran after the VACUUM, so with Microsoft.Data.Sqlite every load of an existing code model database rebuilt the indexes with SQLite's built-in NOCASE, while the session then searched and inserted with the custom (culture aware) NOCASE. The two orders differ for '\' vs digits, '$', '_' and umlauts: lookups missed rows, unique checks let duplicates in and deletes failed with "database disk image is malformed". With the collation registered first the VACUUM at open also re-sorts files that were written with the other SQLite provider. System.Data.SQLite registers no custom collation and is not affected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks. I think I will also add a property to the database to indicate with which version it was created (like the database version). When I detect that the database was created with the other providers then it should be recreated. Robert |
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.
Fixes
SQLite Error 11: 'database disk image is malformed'in the code model when the Microsoft.Data.Sqlite engine is used. That engine is used on ARM, or on x64 when "Use the Microsoft.Data.SQLite engine for the intellisense database" is set under Intellisense.Cause
XDatabase.SetPragmasranVACUUMbeforeSetCollation().VACUUMrebuilds every index with the collation that is registered on the connection at that moment. The schema only stores the nameNOCASE.SetCollationMicrosoftreplacesNOCASEwithString.Compare(x, y, ignoreCase: true). That comparison depends on the culture and sorts\, digits,$,_and umlauts differently from SQLite's built-inNOCASE.OpenFileforValidateSchemaand again for the restore) therefore rebuilt the indexes with the built-inNOCASE. The session then searched, inserted and deleted with the custom one.DeleteOrphanFiles,DeleteFile,UpdateFileContents,Update(XAssembly)andDeleteProjectsNotInSession.System.Data.SQLite registers no custom collation and is not affected.
Fix
SetCollation()now runs before theVACUUM. TheVACUUMat open stays: with the right order it also re-sorts a file that was written with the other engine.Test
VS 2022 experimental instance, RadixWfSDK.slnx:
NOCASE, this file has rows missing fromReferencedGlobals_Name. This is the state that produced the errors before the fix.[ERR], 0 × Error 11. The file written at close passesPRAGMA integrity_checkwith the customNOCASEand has no duplicate project or file rows.Not changed
CurrentDbVersionis unchanged, so files that already contain duplicates are not rebuilt automatically.EditorSettings.json. That run then uses System.Data.SQLite whatever the option says.🤖 Generated with Claude Code