Skip to content

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

Open
@Predhu

Description

@Predhu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions