Skip to content

Fix CLR DATE formatting overflow before 1753 - #223

Draft
masmgr wants to merge 7 commits into
tSQLt-org:mainfrom
masmgr:fix/issue-43-date-overflow
Draft

masmgr wants to merge 7 commits into
tSQLt-org:mainfrom
masmgr:fix/issue-43-date-overflow

Conversation

@masmgr

@masmgr masmgr commented Oct 18, 2026 •

Copy link
Copy Markdown

Refs #43.

tSQLt.TableToText is now implemented in T-SQL, so the public API already handles pre-1753 DATE values on the base branch. The CLR TableToString implementation is no longer called by tSQLt itself and is only reachable through a direct call to the internal tSQLt.Private::TableToString, so the user-facing impact of this change is minimal. This PR fixes the remaining overflow there for consistency.

Problem

Formatting a DATE before 1753-01-01 through CLR TableToString throws SqlDateTime overflow: the DateTime returned by SqlDataReader.GetDateTime was implicitly converted to SqlDateTime, whose range is narrower than DATE.

Change

  • SqlDateToString now takes DateTime and formats it with CultureInfo.InvariantCulture, so the full DATE range comes out as Gregorian yyyy-MM-dd. The other date/time helpers and method names are unchanged.
  • Added a regression test for CLR TableToString covering 0001-01-01, 1752-12-31, 1753-01-01, 9999-12-31, and NULL.

Validation

  • SQL Server 2025 Express (17.0.1145.4), using a temporary unsigned build of the assembly: the new test fails on the base branch with SqlDateTime overflow. With this change, all 43 TableToTextTests pass (SET LANGUAGE us_english, because one existing test expects an English error message).
  • dotnet build (unsigned) passes with 0 warnings and 0 errors.
  • SqlDateToString returns the expected output for the four boundary dates under en-US, ar-SA, and th-TH.

Not tested: SQL Server 2017, non-Gregorian cultures inside SQL Server, the full integration suite.

Format DATE values without converting them to SqlDateTime. Keep regression
coverage focused on CLR TableToString, where the overflow occurred.
@masmgr
masmgr requested a review from a team as a code owner October 18, 2026 06:06
@masmgr
masmgr marked this pull request as draft October 18, 2026 06:32
Run LocalBuild.ps1 and LocalValidate.ps1 against SQL Server 2017, 2019
and 2022 service containers, mirroring the dev container setup with a
throwaway self-signed signing key. Test results are summarized on the
run page and uploaded as artifacts.

Remove build_and_test_on_spawn.yml, which depended on the discontinued
Spawn service and on ant build files that no longer exist.
Add GitHub Actions CI for build and validation on SQL Server (Linux)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant