LinuxDoku / migratordotnet

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

If size is not provided for a byte[] column type, migration fails. #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a migration, with a column that has the type byte[]. eg:        
        new Column("Image", typeof(byte[]))
2. Compile and run migrations
3. The following error occurs:
System.Data.SqlClient.SqlException: Line 1: Length or precision
specification 0 is invalid.
   at Migrator.Migrator.MigrateTo(Int32 version) in
c:\Products\Migrator\app\core\Migrator.cs:line 143
   at Migrator.Migrator.MigrateToLastVersion() in
c:\Products\Migrator\app\core\Migrator.cs:line 182
   at Migrator.NAnt.MigrateTask.ExecuteTask() in
c:\Products\Migrator\app\nant\MigrateTask.cs:line 110
   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()

What is the expected output? What do you see instead?
Expected to see that the migration occured without a hitch.

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

Please provide any additional information below.
If a type is byte[], I would have expected the default of a blob type?
Hence, putting a limit there would seem contrary to expectations.

Looking at TransformationProvider.cs, line 218, it would appear the problem
is with the following lines:
if (column.Type == typeof(byte[]))
{
   if (column.Size <= Convert.ToInt32(byte.MaxValue))
    return TypeToSqlProvider.Binary(Convert.ToByte(column.Size));
   else if (column.Size <= Convert.ToInt32(ushort.MaxValue))
    return TypeToSqlProvider.Blob;
   else
    return TypeToSqlProvider.LongBlob;
}

If you do not assign a size when you define the column, that default size
will be a 0 (if it is a primary type). Hence, following the above logic,
would use a binary type of fixed size of 0. Perhaps the logic should read
as such:

if (column.Type == typeof(byte[]))
{
   if (column.Size <= Convert.ToInt32(byte.MaxValue && column.Size > 0))
    return TypeToSqlProvider.Binary(Convert.ToByte(column.Size));
   else if (column.Size <= Convert.ToInt32(ushort.MaxValue) && column.Size > 0)
    return TypeToSqlProvider.Blob;
   else
    return TypeToSqlProvider.LongBlob;
}

Original issue reported on code.google.com by jason....@gmail.com on 4 Mar 2008 at 1:04

GoogleCodeExporter commented 8 years ago
I have created a patch file of the above bug with test and patch to 
TransformationProvider.cs

Original comment by dko...@gmail.com on 21 Apr 2008 at 3:44

Attachments:

GoogleCodeExporter commented 8 years ago
OK,

I have committed this and the test.

Chers

Original comment by nick.h...@gmail.com on 21 Apr 2008 at 6:02

GoogleCodeExporter commented 8 years ago

Original comment by nick.h...@gmail.com on 21 Apr 2008 at 6:02