System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: bbddfeb773e1c4ba51a19096ae2fc3e48ba03ddc
Title: Cannot read date time values from database when inserting DateTime.MaxValue in combination with SQLiteDateFormats.UnixEpoch
Status: Closed Type: Code_Defect
Severity: Severe Priority: Blocker
Subsystem: Convert Resolution: Fixed
Last Modified: 2023-11-01 16:15:28
Version Found In: 1.0.111 / 1.0.118
User Comments:
anonymous added on 2023-09-18 08:39:48:
When using System.Data.SQLite with SQLiteDateFormats.UnixEpoch I got a bad behavior when saving DateTime.MaxValue using a parameterized query and DbType.DateTime.

Due to the calculation done in Bind_DateTime (SQLite3.cs) which is 

    long value = Convert.ToInt64(dt.Subtract(UnixEpoch).TotalSeconds);

and the fact that DateTime.MaxValue has a millisecond part of 999 the resulting unix epoch value will be 253402300800 but should be 253402300799.
The TotalSeconds property of the timespan is rounded up and so the value overlaps the allowed range of a .NET DateTime object.

If such values are read either by DataReader.GetDateTime() or SQLiteDataAdapter.Fill() it throws ArgumentOutOfRangeException "The added or subtracted value results in an un-representable DateTime".

Stack Trace DataReader:
   at System.DateTime.AddTicks(Int64 value)
   at System.Data.SQLite.SQLiteConvert.UnixEpochToDateTime(Int64 seconds, DateTimeKind kind)
   at System.Data.SQLite.SQLite3.GetDateTime(SQLiteStatement stmt, Int32 index)
   at System.Data.SQLite.SQLiteDataReader.GetDateTime(Int32 i)

Stack Trace DataAdapter:
   at System.DateTime.AddTicks(Int64 value)
   at System.Data.SQLite.SQLiteConvert.UnixEpochToDateTime(Int64 seconds, DateTimeKind kind)
   at System.Data.SQLite.SQLite3.GetDateTime(SQLiteStatement stmt, Int32 index)
   at System.Data.SQLite.SQLite3.GetValue(SQLiteStatement stmt, SQLiteConnectionFlags flags, Int32 index, SQLiteType typ)
   at System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i)
   at System.Data.SQLite.SQLiteDataReader.GetValues(Object[] values)
   at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
   at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
   at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

mistachkin added on 2023-09-19 10:07:58: (text/x-markdown)
Thanks for the report.  This is being looked into.  The fix will be present
in the next release, 1.0.119.0, due out soon.

mistachkin added on 2023-09-24 13:08:03: (text/x-markdown)
Candidate fix is now on trunk.

anonymous added on 2023-10-31 07:21:45: (text/x-markdown)
I merged the fix into our currently used version 1.0.111.0 and did several tests. It works on all platforms.

mistachkin added on 2023-11-01 16:15:28: (text/x-markdown)
Thanks for the update.