Commit cd51a45
committed
CONVERT style codes — common subset, bidirectional, plus money formatting. Datetime → string surface gains 11 new styles (1/101 US, 10/110 USA, 12/112 ISO compact, 102 ANSI, 103 UK, 23 date-only ISO, 126/127 ISO 8601) on top of the existing 0/120/121; the 9 date-only-emit styles share a new FormatDateOnlyStyle helper that every date/datetime/smalldatetime/datetime2/datetimeoffset routes through (so CONVERT(varchar, dt, 112) returns '20260513' regardless of source precision, matching probe). Styles 126/127 emit
T-separated ISO 8601 with source-precision fractional seconds; 127 on datetimeoffset projects to UTC and emits a trailing Z via FormatDateTimeOffsetIso + a +00:00→Z rewrite. String → datetime surface gains a new CoerceStringToDateLikeWithStyle path: per-style DateTime.TryParseExact format-string lists (each with optional trailing-time variants so CONVERT(date, '20260513 14:25:36', 112) works), success re-encodes through datetime2(7) then narrows to target. Parse-failure dispositions are probe-faithful: input that's not a date at all → Msg 241 (general parse fail), input that's a valid date but wrong format for the style → new Msg 9807 ("The input character string does not follow style N…") via new InputCharacterStringStyleMismatch factory. Msg 9807 added to Cast.IsConversionFailure so TRY_CONVERT swallows it. Money → string surface adds CoerceMoneyToStringWithStyle with styles 0 (no commas, 2 decimals — F2), 1 (comma thousands, 2 decimals — N2), 2 (no commas, 4 decimals — F4); smallmoney shares the formatter. ConvertExpression.Run routes by (source category × target category × style present) into the three new paths (date→string, string→date, money→string); all other source-target combinations keep silently ignoring style, matching real SQL Server. Unknown styles within each path raise Msg 281 with the source-family wording (e.g. 99 is not a valid style number when converting from datetime to a character string.). 36 new ConvertTests (datarow-parametrized) cover the new datetime/date/datetime2/datetimeoffset → string styles, the string → date round-trips for 101/112/102/103/23/126/127, the Msg 9807 vs Msg 241 distinction, TRY_CONVERT swallow, money 0/1/2 + smallmoney + negative + Msg 281. CLAUDE.md "Not modeled" entry shrunk to list the residual unsupported style numbers; docs/claude/casting.md gains a full CONVERT style-code section with per-direction tables.1 parent 5fda360 commit cd51a45
7 files changed
Lines changed: 380 additions & 42 deletions
File tree
- SqlServerSimulator.Tests
- SqlServerSimulator
- Errors
- Parser/Expressions
- Storage
- docs/claude
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
175 | 281 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
170 | 181 | | |
171 | 182 | | |
172 | 183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
| 252 | + | |
252 | 253 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
94 | 109 | | |
95 | 110 | | |
96 | 111 | | |
| |||
0 commit comments