Commit febeae6
committed
Collation metadata round-trip (per-DB + per-column whitelist). WWI's last remaining Skipped category —
**Storage**:
- `Database.CollationName : string` (mutable, default `SQL_Latin1_General_CP1_CI_AS`).
- `HeapColumn.Collation : string?` (immutable readonly; null = inherit from database).
**Whitelist** (`Collation.cs`): new `internal static readonly FrozenDictionary<string, string> Recognized` seeded with the two collation names we've encountered in AW + WWI (`SQL_Latin1_General_CP1_CI_AS`, `Latin1_General_100_CI_AS`), each carrying its probe-confirmed human description (consumed by `sys.fn_helpcollations`). Case-insensitive lookup via `StringComparer.OrdinalIgnoreCase`. New `IsRecognized(name)` helper. First FrozenDictionary use in the simulator.
**Parser**:
- `ALTER DATABASE name COLLATE name` (`Simulation.Alter.cs::TryParseAlterDatabaseCollate`) — previously hard-errored on anything other than the default; now validates against the whitelist, stores on `Database.CollationName`, raises `NotSupportedException` on unrecognized names.
- CREATE TABLE column-level `COLLATE name` (`Simulation.Create.cs::ParseOneColumnIntoLists`) — new switch arm in the column-attribute loop accepts the clause after the type position, validates against the whitelist, threads the parsed name to the `HeapColumn` ctor.
**Catalog surface**:
- New `sys.databases` view (9-column subset that tooling actually queries: name / database_id / compatibility_level / collation_name / snapshot_isolation_state / state, plus a single row for the current database — multi-database expansion comes when `USE <db>` lands).
- New `sys.fn_helpcollations()` TVF (`name sysname, description nvarchar(1000)`) — emits one row per `Collation.Recognized` entry. Real SQL Server emits ~5540 rows here; the simulator's shorter list is honest about which names round-trip.
- New `DATABASEPROPERTYEX(db_name, property_name)` built-in scalar in length-18 dispatch — handles the 9 properties common tooling queries (`Collation`, `Status`, `UserAccess`, `IsAutoClose`, `IsAutoShrink`, `Recovery`, `SnapshotIsolationState`, `IsReadCommittedSnapshotOn`, `Version`). NULL db / NULL property / unknown db / unknown property all return NULL (probe-confirmed against SQL Server 2025).
- `sys.columns.collation_name` (`BuiltInResources.EnumerateColumns`) — replaced the captured `defaultCollation` SqlValue with a per-row `CollationFor(col)` helper that consults per-column override → DB default → NULL for non-string types. Same change cascades through INFORMATION_SCHEMA.COLUMNS.
**Loader** (`Storage/Bacpac/ModelXmlReader.cs`):
- `EmitDatabaseOptions` now emits `ALTER DATABASE [simulated] COLLATE name` when the bacpac's `Collation` property is on the whitelist; non-whitelisted names land on `BacpacLoadResult.Warnings` (graceful degradation matches the loader's best-effort contract).
- `TranslateSimpleColumn` reads the bacpac column's `Collation` property and emits a `COLLATE name` clause in the generated CREATE TABLE column DDL when recognized; non-whitelisted names land on Warnings with the clause dropped (column inherits the database default).
**Test additions**:
- `SqlServerSimulator.Tests/CollationMetadataTests.cs` (new, 15 tests): DB collation default + ALTER round-trip via sys.databases + DATABASEPROPERTYEX; column-level COLLATE round-trip via sys.columns + INFORMATION_SCHEMA; per-column inheritance from DB; non-string types return NULL collation_name; column-level unrecognized COLLATE → NotSupportedException; DATABASEPROPERTYEX unknown property / unknown db / NULL args; sys.fn_helpcollations row shape; sys.databases row shape.
- `BacpacLoaderTests.Load_WWI_Database_Collation_Round_Trips` confirms the WWI declaration lands on both `sys.databases.collation_name` and `DATABASEPROPERTYEX`.
- `Load_WWI_Known_Gaps_Recorded_In_Skipped` now asserts `IsFalse(grouped.ContainsKey("SqlDatabaseOptions"))` — zero Skipped categories remaining.
- Existing `Collate_NonDefault_RaisesNotSupported` adjusted to assert the new "recognized list" wording instead of the old "only SQL_Latin1_General_CP1_CI_AS" form.
**Doc updates**:
- `docs/claude/bacpac-prerequisites.md` step 11 captures the bundle in full (storage + whitelist + parser + catalog + loader + non-goal); the WWI gap inventory in step 14 strikes through the `SqlDatabaseOptions` entry; the Status section reads "Zero Skipped categories remain" for WWI.
- `CLAUDE.md` deep-dive pointer updated: WWI now lists zero Skipped categories with an explicit note on the metadata-vs-semantics divergence.SqlDatabaseOptions (the Latin1_General_100_CI_AS declaration) — now lands on Database.CollationName and surfaces through every standard catalog (sys.databases.collation_name, DATABASEPROPERTYEX(name, 'Collation'), sys.columns.collation_name, INFORMATION_SCHEMA.COLUMNS.COLLATION_NAME, sys.fn_helpcollations()). WWI now loads with **zero Skipped categories**. Per-column COLLATE name clauses work end-to-end too. **Important non-goal**: comparison / sort / LIKE / = semantics are unchanged — every string op still routes through Collation.Default (SQL_Latin1_General_CP1_CI_AS rules). The declared name is metadata that round-trips through schema import/export; fully modeling per-collation comparison/sort algorithms is a separate, much larger project.1 parent 6ac3196 commit febeae6
14 files changed
Lines changed: 481 additions & 40 deletions
File tree
- SqlServerSimulator.Tests.Internal/Storage
- SqlServerSimulator.Tests
- SqlServerSimulator
- Parser
- Expressions
- Simulation
- Storage
- Bacpac
- docs/claude
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
619 | | - | |
| 619 | + | |
620 | 620 | | |
621 | 621 | | |
622 | 622 | | |
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
638 | 662 | | |
639 | 663 | | |
640 | 664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
0 commit comments