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
NH-4093 - Running Unit tests against SQLite fails on numerous (22) datetime/UTC related tests. #1362
Comments
As for the previous behavior for st.Parameters[index].Value = new DateTime(dateValue.Year, dateValue.Month, dateValue.Day, dateValue.Hour, dateValue.Minute, dateValue.Second); By commonizing everything with what used to be I think changing the ternary is a good idea to always force This issue has been previously reported to the system.data.sqlite issue tracker. The suggestion of adding to the sqlite query string The code in the return DateTime.SpecifyKind(DateTime.ParseExact(
dateText, _datetimeFormats,
DateTimeFormatInfo.InvariantInfo,
kind == DateTimeKind.Utc ?
DateTimeStyles.AdjustToUniversal :
DateTimeStyles.None),
kind); where For SQLite, changing all DateTime parameters at |
Your taking behavior of what is now
The SQLite issue is closed as "as design". I think they have not realized there was actually something wrong, even if the opener trouble was solved by switching to var date = DateTime.ParseExact(
dateText, _datetimeFormats,
DateTimeFormatInfo.InvariantInfo,
DateTimeStyles.AdjustToUniversal);
if (kind == DateTimeKind.Local && date.Kind == DateTimeKind.Utc)
date = date.ToLocalTime();
return DateTime.SpecifyKind(date, kind); It would not convert back and forth local dates because their current string representation with SQLite ISO8601 does not include an offset, so
This will solve our test cases, but may cause issues to users storing only UTC dates combined with |
Instead of further guessing, I made a unit test that checks all the combinations that I could think of: https://gist.github.com/ngbrown/195e09681572371011fb2c78c5fcf04d The best combination is: private int _optionToStringInSqLite = 1; // Currently implemented in System.Data.SQLite
private int _optionToDateTimeInSqLite = 1; // Currently implemented in System.Data.SQLite
//private int _optionToDateTimeInSqLite = 2; // proposed by frederic
//private int _optionToDateTimeInSqLite = 3; // variation proposed by nathan - would let UTC marker back through on read if saved
//private int _optionAdjustCommand = 1; // no driver change
private int _optionAdjustCommand = 2; // all date kind to Unspecified
//private int _optionAdjustInType = 1; // current state in NHibernate
private int _optionAdjustInType = 2; // proposed by Nathan Changing
The unit tests show that the my pull request as currently implemented is will continue to work in all scenarios even if the |
I had not seen that SQLite |
@hazzik, it does not look to me as a regression, but as an old overlooked trouble. Testing the 4.1.x branch, there is already the Adding a test into that branch for timestamp shows it is failing the same than current 5.0 with SQLite and an utc date as input. And since current |
The more I look into the less I am agreed with trying to address this. It looks like we are going to add our own layer of mess above SQLite inconsistent date handling for "compensating" it at least within NHibernate, but what is in for any direct access to the actually stored data an app may do? I am still thinking the very most we should do is to only override the SQLite driver |
I have submitted a ticket on SQLite driver side just in case. |
There is a third SQLite datetime related connection string parameter I had overlooked till now: So now I think the right way to fix this issue is to instruct SQLite to be datetime kind agnostic by using |
Closed, work as designed, though the closer comment suggests he is agreeing it would be better to change that, but he is unwilling to do a breaking change. Anyway I think we have a valid work-around for this System.Data.SQLite glitch as done in #1378, with an easy recommendation to give to who would face the issue, and which is included in documentation by this PR. |
This is my session factory configuration, it works for me. sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ConnectionString(cs => cs.Is("Data Source=:memory:;Version=3;New=True;DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;")))
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(TigerBillingModule))))
.CurrentSessionContext<ThreadStaticSessionContext>()
.ExposeConfiguration(cfg => inMemDbConfiguration = cfg)
.BuildSessionFactory(); |
Nathan Brown created an issue — 12th October 2017, 6:17:57:
Frédéric Delaporte added a comment — 12th October 2017, 11:39:20:
Nathan Brown added a comment — 12th October 2017, 19:08:37:
Frédéric Delaporte added a comment — 12th October 2017, 20:04:57:
The text was updated successfully, but these errors were encountered: