minhphien / migratordotnet

Automatically exported from code.google.com/p/migratordotnet
0 stars 0 forks source link

Setting default DateTime value fails #72

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a migration for SQLite
2. Create a column with a type of System.Data.DbType.DateTime
3. Assign a default value of DateTime.Now
4. Run the migration

What is the expected output? What do you see instead?
Expected that the default value will be the current date.

What version of the product are you using? On what operating system? With 
what .NET implementation/version?
Using version 0.70 on Windows XP, .NET 3.5

What database and version are you seeing this issue on?
SQLite 3

Please provide any additional information below.
Here's the output from the NAnt task.  When I don't set the default value, 
it works great.

NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/Development/Tremolo/trunk/Code/Tremolo/default.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: migrate 

[loadtasks] Scanning assembly "Migrator.NAnt" for extensions.

build:

      [csc] Compiling 3 files to 
'C:\Development\Tremolo\trunk\Code\Tremolo\Tremolo.Migrations\bin\Tremolo.M
igrations.dll'.

migrate:

  [migrate] Current version : 1
  [migrate]     1 001_ create user table
  [migrate]       [Warning] SQLite error
  [migrate] near "/": syntax error
  [migrate]       Error in migration 1 : SQLite error
  [migrate] near "/": syntax error
  [migrate] SQLite error
  [migrate] near "/": syntax error
  [migrate]    at System.Data.SQLite.SQLite3.Prepare(String strSql, 
SQLiteStatement previous, String& strRemain)
  [migrate]    at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
  [migrate]    at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 
index)
  [migrate]    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
  [migrate]    at 
Migrator.Providers.TransformationProvider.ExecuteNonQuery(String sql) in 
c:\work\other projects\migratordotnet\migratordotnet-
trunk\src\Migrator.Providers\TransformationProvider.cs:line 514
  [migrate]    at Migrator.Providers.TransformationProvider.AddTable(String 
table, String columns) in c:\work\other 
projects\migratordotnet\migratordotnet-
trunk\src\Migrator.Providers\TransformationProvider.cs:line 131
  [migrate]    at Migrator.Providers.TransformationProvider.AddTable(String 
name, Column[] columns) in c:\work\other 
projects\migratordotnet\migratordotnet-
trunk\src\Migrator.Providers\TransformationProvider.cs:line 171
  [migrate]    at Tremolo.Migrations._001_CreateUserTable.Up() in 
c:\Development\Tremolo\trunk\Code\Tremolo\Tremolo.Migrations\001_CreateUser
Table.cs:line 14
  [migrate]    at Migrator.MigrateUp.Migrate(Migration migration) in 
c:\work\other projects\migratordotnet\migratordotnet-
trunk\src\Migrator\MigrateUp.cs:line 37
  [migrate]    at Migrator.Migrator.MigrateTo(Int32 version) in 
c:\work\other projects\migratordotnet\migratordotnet-
trunk\src\Migrator\Migrator.cs:line 154
  [migrate] Rolling back to migration 0

BUILD FAILED - 2 non-fatal error(s), 0 warning(s)

INTERNAL ERROR

System.Data.SQLite.SQLiteException: SQLite error
near "/": syntax error
   at System.Data.SQLite.SQLite3.Prepare(String strSql, SQLiteStatement 
previous, String& strRemain)
   at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
   at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
   at Migrator.Providers.TransformationProvider.ExecuteNonQuery(String sql) 
in c:\work\other projects\migratordotnet\migratordotnet-
trunk\src\Migrator.Providers\TransformationProvider.cs:line 514
   at Migrator.Providers.TransformationProvider.AddTable(String table, 
String columns) in c:\work\other projects\migratordotnet\migratordotnet-
trunk\src\Migrator.Providers\TransformationProvider.cs:line 131
   at Migrator.Providers.TransformationProvider.AddTable(String name, 
Column[] columns) in c:\work\other projects\migratordotnet\migratordotnet-
trunk\src\Migrator.Providers\TransformationProvider.cs:line 171
   at Tremolo.Migrations._001_CreateUserTable.Up() in 
c:\Development\Tremolo\trunk\Code\Tremolo\Tremolo.Migrations\001_CreateUser
Table.cs:line 14
   at Migrator.MigrateUp.Migrate(Migration migration) in c:\work\other 
projects\migratordotnet\migratordotnet-trunk\src\Migrator\MigrateUp.cs:line 
37
   at Migrator.Migrator.MigrateTo(Int32 version) in c:\work\other 
projects\migratordotnet\migratordotnet-trunk\src\Migrator\Migrator.cs:line 
165
   at Migrator.Migrator.MigrateToLastVersion() in c:\work\other 
projects\migratordotnet\migratordotnet-trunk\src\Migrator\Migrator.cs:line 
89
   at Migrator.NAnt.MigrateTask.Execute(Assembly asm) in c:\work\other 
projects\migratordotnet\migratordotnet-
trunk\src\Migrator.NAnt\MigrateTask.cs:line 122
   at Migrator.NAnt.MigrateTask.ExecuteTask() in c:\work\other 
projects\migratordotnet\migratordotnet-
trunk\src\Migrator.NAnt\MigrateTask.cs:line 113
   at NAnt.Core.Task.Execute()
   at NAnt.Core.Target.Execute()
   at NAnt.Core.Project.Execute(String targetName, Boolean 
forceDependencies)
   at NAnt.Core.Project.Execute()
   at NAnt.Core.Project.Run()

Please send bug report to nant-developers@lists.sourceforge.net.

Total time: 0.7 seconds.

Original issue reported on code.google.com by ric...@gmail.com on 9 Oct 2008 at 2:53

GoogleCodeExporter commented 9 years ago
can you provide relevant codesnippets to reproduce?

Original comment by dip...@gmail.com on 10 Oct 2008 at 11:52

GoogleCodeExporter commented 9 years ago
I can post some:
        Database.AddTable("News", 
            new Column("id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
            new Column("title", DbType.String, 50),
            new Column("text", DbType.String, 50),
            new Column("created_at", DbType.DateTime),
            new Column("updated_at", DbType.DateTime)
        );
So, here's a wrong way: 
        Database.Insert("News", 
                        new string[] {"title", "text", "created_at", "updated_at"},
                        new string[] {"First Title", "First Text", 
DateTime.Now.ToString(), DateTime.Now.ToString() } );

Here's a right way:
DateTime.Now.ToString("yyyy-MM-dd")

Basically, you should specify the date format you DB supports, whether its 
yyyy-MM-
dd, or dd-MM-yyyy or slashes instead of dashes. Whatever you need.
But i think that's still a wrong way of doing it all. You should use object[] 
instead 
of string[] in Database.Insert().
If you want a patch, let me know via email oleksandr.petrov@gmail.com 
I think i can handle this one, if it falls under your ideology, and than you 
should 
check the type of the required object. For Db DateTime you use 
DateTime->object->cast 
back to datetime. 

Original comment by oleksand...@gmail.com on 30 May 2010 at 3:41