tobiasschulz / csharp-sqlite

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

Missing Type DateTime.MinValue #61

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
DateTime.MinValue causes an error on save

ToFileTime is invalid on MinValue, throwing an exception - but that's the 
default value DateTime is assigned and when using an ORM like NHibernate this 
causes problems.

I'm not sure what the suggested fix is (It's not to change all my code, this 
works fine in un-managed SQLite!) - perhaps check that DateTime is in bounds 
before casting? Not using Filetime?

Original issue reported on code.google.com by RobAshto...@gmail.com on 7 Jun 2010 at 10:16

GoogleCodeExporter commented 9 years ago
Can you give a little more detail on how to reproduce this error

Original comment by noah.hart@gmail.com on 7 Jun 2010 at 10:46

GoogleCodeExporter commented 9 years ago
Uh oh! It's a bit difficult as I'm going through NHibernate (I have a test).

Let me create a test project and I'll paste some code here

Original comment by RobAshto...@gmail.com on 7 Jun 2010 at 10:55

GoogleCodeExporter commented 9 years ago

Original comment by noah.hart@gmail.com on 7 Jun 2010 at 10:59

GoogleCodeExporter commented 9 years ago
class Program
    {
        static void Main(string[] args)
        {
            using (var connection = new SqliteConnection("uri=file://:memory:,Version=3"))
            {
                connection.Open();

                using (var schemaCommand = connection.CreateCommand())
                {
                    schemaCommand.CommandText = @"
                    create table TestTable (
                        Id  integer,
                       TestTime DATETIME not null,
                       primary key (Id));";

                    schemaCommand.ExecuteNonQuery();                    
                }

                using (var insertCommand = connection.CreateCommand())
                {
                    insertCommand.CommandText = @"
                        INSERT INTO TestTable (TestTime) VALUES ( @testTime )
                    ";
                    insertCommand.Parameters.Add("@testTime", DateTime.MinValue);
                    insertCommand.ExecuteNonQuery();
                }
            }
        }
    }

Original comment by RobAshto...@gmail.com on 7 Jun 2010 at 11:14

GoogleCodeExporter commented 9 years ago
I hope I've provided enough info, I need to hit bed as it's 00:30am over here.

Thanks much for the prompt responses, gives me confidence that I'll be able to 
carry on using this in this project (YES! No x86/x64 problems!!)

Original comment by RobAshto...@gmail.com on 7 Jun 2010 at 11:27

GoogleCodeExporter commented 9 years ago
Fixed in  changeset:   70:76bfa95f3d81
date:        Mon Jun 07 18:38:02 2010 -0700

Original comment by noah.hart@gmail.com on 8 Jun 2010 at 1:38