luan-nvg / csharp-sqlite

Automatically exported from code.google.com/p/csharp-sqlite
Other
0 stars 0 forks source link

Date format Error #74

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using the above code with a Windows XP machine and the UK locale, create the 
following table:

CREATE TABLE TASKS ( TASKID INTEGER PRIMARY KEY, PARENTTASKID INTEGER, 
DESCRIPTION TEXT, STATUS INTEGER, CREATED DATETIME )

Insert a single record:

INSERT INTO TASKS( TASKID, PARENTTASKID, DESCRIPTION, STATUS, CREATED ) values 
(... etc ..., "03/24/2010 01:23:45") <--this might be the issue

2. Run the following code:

SqliteCommand cmd = con.CreateCommand();

cmd.CommandText = "select * from TASKS";
DataTable dataTable = new DataTable();
SqliteDataAdapter dataAdapter = new SqliteDataAdapter();
dataAdapter.SelectCommand = cmd;
dataAdapter.Fill(dataTable);

There will be a conversion error!!

What is the expected output? What do you see instead?

No error should occur.

What version of the product are you using? On what operating system?

Latest stable download source.

Please provide any additional information below.

Altering the original code (circa line 213 in SqliteDataReader.cs) to the 
following, will correct the error: (for me)

data_row[i] = Sqlite3.sqlite3_column_text (pVm, i);

// If the column was declared as a 'date' or 'datetime', let's play
// nice and return a DateTime (version 3 only).
if (declmode[i] == 2)
{
  //data_row[i] = DateTime.Parse((string)data_row[i]); <---assumes US is default, fails in the UK
  System.Globalization.CultureInfo usCulture = new System.Globalization.CultureInfo("en-US");
  data_row[i] = DateTime.Parse((string)data_row[i], usCulture);
}
break;

Original issue reported on code.google.com by mem...@gmail.com on 29 Jul 2010 at 2:54

GoogleCodeExporter commented 8 years ago
Does this also work for you?

data_row[i] = DateTime.Parse((string)data_row[i], 
System.Globalization.CultureInfo.InvariantCulture);

Original comment by noah.hart@gmail.com on 29 Jul 2010 at 8:32

GoogleCodeExporter commented 8 years ago
Indeed, that has worked. It's cleaner than my suggestion too :-)

Original comment by mem...@gmail.com on 30 Jul 2010 at 10:52

GoogleCodeExporter commented 8 years ago
Fixed with changeset 78fcda0bf7     Fri Jul 30 06:29:20 2010 -0700
Issue 74:    Date format Error with non US Formats

Original comment by noah.hart@gmail.com on 30 Jul 2010 at 1:31