Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tSQLt.AssertEqualsTable fails when a DATE column has a value less than 1753-01-01 #43

Open
Predhu opened this issue May 3, 2019 · 0 comments
Labels

Comments

@Predhu
Copy link

Predhu commented May 3, 2019

We are using 0001-01-01 (the minimum value for the DATE data type in SQL Server 2017) in some tables. Asserting table equals fails with the following error when this (or any value less than 1753-01-01 is present:

(Error) A .NET Framework error occurred during execution of user-defined routine or aggregate "Private": 
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
System.Data.SqlTypes.SqlTypeException: 
   at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value)
   at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value)
   at tSQLtCLR.tSQLtPrivate.getTableStringArray(SqlDataReader reader, SqlString PrintOnlyColumnNameAliasList)
   at tSQLtCLR.tSQLtPrivate.TableToString(SqlString TableName, SqlString OrderOption, SqlString ColumnList)
.[16,1]{tSQLt.TableToText,8}

It seems that the whole thing fails when the table is serialize in tSQLt.TableToText when the assertion fails.

How to reproduce:

CREATE TABLE #Table (DateColumn DATE);
CREATE TABLE #Table2 (DateColumn DATE);

-- Succeeds
TRUNCATE TABLE #Table;
TRUNCATE TABLE #Table2;
INSERT INTO #Table (DateColumn) VALUES ('1753-01-01');
INSERT INTO #Table2 (DateColumn) VALUES ('2000-01-01');
EXEC tSQLt.AssertEqualsTable N'#Table', N'#Table2';

-- Fails
TRUNCATE TABLE #Table;
TRUNCATE TABLE #Table2;
INSERT INTO #Table (DateColumn) VALUES ('1752-12-31');
INSERT INTO #Table2 (DateColumn) VALUES ('2000-01-01');
EXEC tSQLt.AssertEqualsTable N'#Table', N'#Table2';

-- Succeeds
TRUNCATE TABLE #Table;
TRUNCATE TABLE #Table2;
INSERT INTO #Table (DateColumn) VALUES ('0001-01-01');
INSERT INTO #Table2 (DateColumn) VALUES ('0001-01-01');
EXEC tSQLt.AssertEqualsTable N'#Table', N'#Table2';

Environment:

  • SQL Server 2017 Developer
  • .NET Framework 4.5.2
  • Windows 10 Enterprise
@Predhu Predhu changed the title tSQLt.AsserTableEquals fails when a DATE column has a value less than 1753-01-01 tSQLt.AssertEqualsTable fails when a DATE column has a value less than 1753-01-01 May 3, 2019
@mbt1 mbt1 added the bug label Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants