Closed s952163 closed 8 years ago
Thanks. This is actually very easy to reproduce with our current SQLite unit tests. And there are fixes... But the stacktrace is not ours, so needs a bit more exploration how we could get workaround.
Hmm... If the standard SQLite doesn't have datetime... One hack in the meanwhile would be saving datetime values also to int column and compare them.
With SQLite (at least version 1.0.102) you should have an option to create DateTime
data-type. Would this be enough?
@Thorium Again, thanks for looking into this and the prompt reply. Indeed, you have referenced my own question/answer on SO. It is generally preferable to use DateTime, while SQLite doesn't have a concept of DateTime, it's very flexible in allowing basically any type as a column. So as long as Linq or SQLProvider can correctly translate back to .NET DateTime, it will work. However, using DateTime can be also tricky: see this [ Question (keep quiting myself ;-). Because SQLite tends to deal with UTC and although it will happily store anything, it will give back UTC and that can be confusing, when doing comparison. So the idea of storing DateTime as string (int can have its own issues) is a quite asafe and portable way to deal with Dates. I also noticed that the stack trace goes to IQueryable and FSharp.Linq. If the issue is actually even deeper than a fix is even more preferable.
What would you think of this fix candidate:
query {
for r in table6 do
where (DateTime.Parse(r.Date1) > DateTime.Parse("2016-12-08 12:00:00"))
select (r.Date1)
} |> Seq.toList
...and then we expect that the database is actually capable of handling implicit conversion? So the SQL will be just as-is, not any casting, as casting may lead to not hitting indexes and other kind of complex problems that you can see in EntityFramework.
Nice! This is not valid Linq right now, correct? I think this should work for the most common case of storing dates as text so I'm all for it. The issue of other types of string comparisons will remain I suspect but as I cannot offer any deep insight on what was going wrong in the first place this looks to me a smart workaround.
Nuget package 1.0.32 has this feature.
:+1: Will test. thx. Works Nice! :+1:
Description
When doing comparison on date strings in SQLite, greater than or smaller than results in:
Expected behavior
Sort based on string comparison.
Actual behavior
Related information
.NET 4.6