LinuxDoku / migratordotnet

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

SQLite.NET parse problems #143

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
--- What steps will reproduce the problem?
1. Create DB. Create table with primary key
2. Create migration (rename table). 

--- What is the expected output? What do you see instead?
Migrator not correct parse sql. Last ")" in "primary key (Id)" lost.

--- Please use labels and text to provide additional information.
Change SQLiteTransformationProvider.cs as described below:

public string[] ParseSqlColumnDefs(string sqldef) 
        {
            if (String.IsNullOrEmpty(sqldef)) 
            {
                return null;
            }

            sqldef = sqldef.Replace(Environment.NewLine, " ");
            int start = sqldef.IndexOf("(");
            //begin primary key (column) patch
            int end = sqldef.IndexOf("))");
            if (end == -1)
                end = sqldef.IndexOf(")");
            else
            {
                end++;
            }
            //end primary key (column) patch

            sqldef = sqldef.Substring(0, end);
            sqldef = sqldef.Substring(start + 1);

            string[] cols = sqldef.Split(new char[]{','});
            for (int i = 0; i < cols.Length; i ++) 
            {
                cols[i] = cols[i].Trim();
            }
            return cols;
        }

Original issue reported on code.google.com by it.advis...@gmail.com on 12 Mar 2010 at 4:51

GoogleCodeExporter commented 8 years ago
I can confirm this.  It appears that sqlite allows 2 different methods of 
creating a primary key:
1.) inline: ... (id integer primary key, columntwo integer...
2.) at the end: ... columnx integer, primary key (id))

It then appears that the migrator.net only allows for 1 and not 2.  NHibernate 
seems to default to 2 as all my db's have been created by nhibernate.

my fix was simply to change the 'IndexOf' for the end variable to 'LastIndexOf'.

Original comment by garri...@gmail.com on 10 Jun 2010 at 6:41