Bug 46929

Summary: Datetime error on Mono.data.Sqlite
Product: [Mono] Class Libraries Reporter: Marco <mpiralli>
Component: Mono.Data.SqliteAssignee: Marek Safar <masafa>
Status: VERIFIED FIXED    
Severity: normal CC: andy.joiner, jurij.rozanec, luis.aguilera, masafa, matthew.leibowitz, mfulker, mono-bugs+AddonSite, mono-bugs+mono, mpiralli, mustapha.amchech, peter.collins
Priority: ---    
Version: master   
Target Milestone: C9SR0   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: Yes
Last known good build:
Attachments: Bug reproduction test case

Description Marco 2016-11-14 15:45:51 UTC
Following the last upgrade of the the xamrin environment is no longer possible to perform the queries, which filter is composed with datetime condition.

While leaving all conditions unchanged:  same source code, same database structure and the data in the tables; the solution compiled with the previous framework (until August 2016) return always the correct records, after install the last framework the query return 0 result.

using (SqliteCommand cmd = conn.CreateCommand())
{
  cmd.CommandText = " SELECT * FROM SP_ARTMGZ WHERE DATE_SPED=@DATESPED ";
  cmd.Parameters.Clear();
  cmd.Parameters.AddWithValue("@DATESPED", dtDateSped);
  conn.Open();
  using (SqliteDataAdapter da = new SqliteDataAdapter(cmd))
  {
   da.Fill(result);
  }
}


=== Xamarin Studio Professional ===
Version 6.1.2 (build 44)
Installation UUID: 8716ded3-7f56-49d6-b5ac-f2c7597eef3f
Runtime:
Microsoft .NET 4.0.30319.42000
GTK+ 2.24.26 (Light theme)
GTK# 2.12.38
=== NuGet ===
Versione: 3.4.3.0
=== Xamarin.Android ===
Versione: 7.0.2.37 (Visual Studio Professional)
Android SDK: C:\Users\Giovanni\AppData\Local\Android\android-sdk
Versione di Android supportate:
4.0.3  (livello API 15)
4.4    (livello API 19)
4.4.87 (livello API 20)
5.0    (livello API 21)
5.1    (livello API 22)
6.0    (livello API 23)
7.0    (livello API 24)

Versione degli strumenti SDK: 25.2.2
Versione degli strumenti della piattaforma SDK: 25
Versione degli strumenti di compilazione SDK: 23.0.3
Comment 1 Jurij Rožanec 2016-11-25 12:28:12 UTC
Created attachment 18674 [details]
Bug reproduction test case

Test case that reproduces bug under
-
Xamarin 4.2.1.64
Xamarin.Android 7.0.2.37
Mono: 4.6.2
-
, but not limited to.

Test case passes under
-
Xamarin 4.1.1.3
Xamarin.Android 6.1.1.1
Mono: 4.4
-
, and earlier versions
Comment 2 Matthew Leibowitz 2017-02-10 22:40:21 UTC
This is a bug, and is a result of these two commits:
https://github.com/mono/mono/commit/a90d5d8e1530884e22b66f320393484e3ae17f14
https://github.com/mono/mono/commit/095701df579144a33d49fbe08ede8c7d3640a9a8

These are the related issues:
https://bugzilla.xamarin.com/show_bug.cgi?id=40603
https://bugzilla.xamarin.com/show_bug.cgi?id=44349

Basically, the way in which dates are saved was changed:
OLD: yyyy-MM-dd HH:mm:ss.FFFFFFF
NEW: yyyy-MM-dd HH:mm:ss.FFFFFFFK

For whatever reason this was changed, it is "incorrect" with regards to SQLite docs:
https://www.sqlite.org/datatype3.html

> SQLite does not have a storage class set aside for storing dates and/or times.
> Instead, the built-in Date And Time Functions of SQLite are capable of storing 
> dates and times as TEXT, REAL, or INTEGER values:
> 
>   - TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
>   - REAL as Julian day numbers, the number of days since noon in Greenwich on
>     November 24, 4714 B.C. according to the proleptic Gregorian calendar.
>   - INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Comment 3 Marek Safar 2017-02-24 15:27:09 UTC
Fixed in master and upcoming C9 updates
Comment 4 Marek Safar 2017-02-24 15:39:38 UTC
*** Bug 52427 has been marked as a duplicate of this bug. ***
Comment 5 Peter Collins 2017-03-09 20:41:00 UTC
Verified fixed using the attached test case against monodroid/cycle9/3a62f1ea1f6.
Comment 6 Andy Joiner 2017-06-28 15:46:28 UTC
Fix published in Xamarin.Android 7.2

https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.2/