Bug 5078 - Sqlite DateTime retrieved as String
Summary: Sqlite DateTime retrieved as String
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2012-05-14 17:44 UTC by Datadec Online
Modified: 2012-05-21 17:50 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Datadec Online 2012-05-14 17:44:14 UTC
When I retrieve a DATETIME column from SQLite is typed as System.String instead of System.DateTime. Behaviour is happening since I upgraded MonoDroid to version 4.2.
Comment 1 Datadec Online 2012-05-16 07:06:41 UTC
private void Test()
    {
      Mono.Data.Sqlite.SqliteConnection cn;
      Mono.Data.Sqlite.SqliteCommand cm;
      Mono.Data.Sqlite.SqliteParameter dp1;
      Mono.Data.Sqlite.SqliteParameter dp2;
      Mono.Data.Sqlite.SqliteDataReader dr;
      DateTime d;

      string dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "testdb.db");

      cn = new Mono.Data.Sqlite.SqliteConnection("Data Source=" + dbPath);
      cn.Open();

      cm = cn.CreateCommand();
      cm.CommandText = "DROP TABLE TEST";
      cm.ExecuteNonQuery();
      cm.Dispose();

      cm = cn.CreateCommand();
      cm.CommandText = "CREATE TABLE TEST (F1 INTEGER, F2 DATETIME)";
      cm.ExecuteNonQuery();
      cm.Dispose();

      cm = cn.CreateCommand();
      cm.CommandText = "INSERT INTO TEST (F1, F2) VALUES (:F1, :F2)";

      dp1 = cm.CreateParameter();
      dp1.ParameterName = ":F1";
      dp1.Value = 1;
      cm.Parameters.Add(dp1);

      dp2 = cm.CreateParameter();
      dp2.ParameterName = ":F2";
      dp2.Value = DateTime.Now;
      cm.Parameters.Add(dp2);

      cm.ExecuteNonQuery();
      cm.Dispose();

      cm = cn.CreateCommand();
      cm.CommandText = "SELECT F1, F2 FROM TEST WHERE F1 = 1";
      dr = cm.ExecuteReader();

      dr.Read();

      string type;
      type = dr.GetFieldType(dr.GetOrdinal("F2")).ToString();
      /*
      type = "System.DateTime" in version 4.0.6 or prior.
      type = "System.String" in version 4.2.1".
      */
      d = dr.GetDateTime(dr.GetOrdinal("F2"));
      dr.Close();

      dr.Dispose();
      cn.Close();
      cn.Dispose();
    }
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-05-18 08:35:40 UTC
Fixed (unit test included).

mobile-master: f5127609b28407b865b7f15d21d2fa1bad20f25f
Comment 3 Datadec Online 2012-05-18 11:05:16 UTC
Hi,

How can I update my MonoDroid installation to have this issue fixed? I don't see any update.

Regads,
Javier Gutiérrez
Comment 4 Jonathan Pryor 2012-05-21 17:50:32 UTC
This will be included in the forthcoming 4.2.2 release.