From c72ff67dfbd0f588b9959ab59892fb2aeb4ec6bb Mon Sep 17 00:00:00 2001 From: Hansjoerg Petriffer Date: Wed, 28 Oct 2026 10:22:41 +0100 Subject: [PATCH] [Vsintegration] XDatabase.SetPragmas: register the collation before the 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 --- src/VisualStudio/XSharpCodeModelXs/Database/XDatabase.prg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/XSharpCodeModelXs/Database/XDatabase.prg b/src/VisualStudio/XSharpCodeModelXs/Database/XDatabase.prg index 9acc5315da..63804a5941 100644 --- a/src/VisualStudio/XSharpCodeModelXs/Database/XDatabase.prg +++ b/src/VisualStudio/XSharpCodeModelXs/Database/XDatabase.prg @@ -167,9 +167,12 @@ STATIC METHOD SetPragmas(oConn AS DbConnection) AS VOID Log("Set the pragmas for the database") USING VAR oCmd := CreateCommand("PRAGMA foreign_keys = ON", oConn) oCmd:ExecuteNonQuery() + // Register the collation before the VACUUM: the VACUUM rebuilds the NOCASE indexes with the collation + // that is registered at that moment. With the built-in NOCASE the indexes no longer match the custom + // NOCASE of Microsoft.Data.Sqlite, lookups miss rows and SQLite reports "database disk image is malformed". + oConn:SetCollation() oCmd:CommandText := "VACUUM" oCmd:ExecuteNonQuery() - oConn:SetCollation() CATCH e AS Exception Log("Error setting pragmas") XSettings.Exception(e)