LinuxDoku / migratordotnet

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

Floating Point Columns Size #103

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
How can we define the right size of the floating point columns since we 
must set the integer and the decimal parts? In MySQL Decimal(15,2) is 
different of Decimal (15,8) but both have size 15.

Am I missing something? 

Thank you

Original issue reported on code.google.com by cass...@gmail.com on 9 Apr 2009 at 2:37

GoogleCodeExporter commented 8 years ago
I suggest the following class for specify the size of the field of table:

    public class FieldSize
    {
        public int Length { get; set; }
        public int? Precision { get; set; }

        public FieldSize(int length)
        {
            Length = length;
        }

        public static implicit operator FieldSize(int i)
        {
            return new FieldSize(i);
        }

        /// <summary>
        /// string representation of the Length (without Precision)
        /// can be used to build a sql-query
        /// </summary>
        public string GetLength()
        {
            return Length.ToString();
        }

        /// <summary>
        /// string representation of the Length (with Precision)
        /// can be used to build a sql-query
        /// </summary>
        public string GetLengthWithPrecision()
        {
            return Precision.HasValue ?
                string.Format("{0},{1}", Length, Precision) :
                GetLength();
        }

Original comment by dima117a@gmail.com on 26 Jun 2009 at 4:31

GoogleCodeExporter commented 8 years ago
Hi. Thank you for your sugestion but I found that migrator already had most of 
the 
code to make it work, so I just created new methods and slightly modified 
others to 
make it work.

I think that your code would be a better choice since it is better designed, 
but like 
I said, migrator size handing is more primitive and I would have to change it a 
lot 
too.

Thank you

I'm attaching the files that I've changed. Use it at your own risk! :)

Original comment by cass...@gmail.com on 15 Sep 2009 at 7:56

Attachments:

GoogleCodeExporter commented 8 years ago
Thank you for your reply!

When I wrote to you my last comment, I was not  familiar with the code.
I made a assumption about how to implement the  building of SQL for columns. 
After
that long time I studied the code and now I see that my assumption proved 
incorrect.

I made implementation of this functional for yourself. My implementation is very
similar to yours.

Difference is that instead of several fields in the class 'Column' I use one 
field of
type 'ColumnType'
(http://code.google.com/p/ecm7migrator/source/browse/trunk/ECM7.Migrator.Framewo
rk/ColumnType.cs).

ColumnType object can be created implicit from DbType object. Also I wrote 
extension
methods for DbType and for create ColumnType can use this syntax:
DbType.Decimal.WithSize(10, 2)
DbType.String.WithSize(20)

Also, I made other changes in code, but I'm not sure that these changes are 
needed to
other people. I made separate project with my changes. 

If you're interested, the url of my project is
http://ecm7migrator.googlecode.com/svn/trunk/

Thank you

Sorry for my English

Original comment by dima117a@gmail.com on 15 Sep 2009 at 11:32

GoogleCodeExporter commented 8 years ago
Hi. Like the previous one, your code is more flexible than mine. I did it in 
that way 
because we don't see new database types everyday. So I think I will not have to 
change 
it in a long time.

This case is solved but let's keep contact.

And english is not my first language too, so, sorry too.

Original comment by cass...@gmail.com on 18 Sep 2009 at 12:57