Пример #1
0
        private List <SColumn> GetBaseColumns(DbConn dbconn, string tableid)
        {
            string         sql       = @"select SC.object_id,SC.name,SC.column_id,SC.user_type_id,ST.name as typename,
                                    SC.max_length,SC.precision,SC.scale,SC.is_nullable,
                                    SC.is_identity,IC.seed_value,IC.increment_value,IC.last_value,
                                    SC.default_object_id,DFC.definition,EP.value as des
                                    from sys.all_columns   SC 
                                    left join sys.types ST on SC.user_type_id=ST.user_type_id
                                    left join sys.identity_columns IC on SC.object_id=IC.object_id and SC.column_id=IC.column_id
                                    left join sys.default_constraints DFC on SC.default_object_id=DFC.object_id
                                    left join sys.extended_properties EP on EP.minor_id=SC.column_id and SC.object_id=EP.major_id and EP.name='MS_Description'
                                    where SC.object_id=@objid";
            DataTable      tbcolumns = dbconn.SqlToDataTable(sql, new { objid = tableid });
            List <SColumn> columns   = new List <SColumn>();

            foreach (DataRow dr in tbcolumns.Rows)
            {
                string    desc      = dr["des"].ToString();
                FieldType fieldtype = DbFieldTypeHelper.SqlServerGetFieldType(
                    dr["typename"].ToString(),
                    Convert.ToInt32(dr["precision"]),
                    Convert.ToInt32(dr["scale"]),
                    Convert.ToInt32(dr["max_length"]));
                columns.Add(new SColumn()
                {
                    name        = dr["name"].ToString(),
                    allownull   = Utils.Converter.ObjToBool(dr["is_nullable"]),
                    description = desc,
                    title       = string.IsNullOrEmpty(desc) ? dr["name"].ToString() : desc,
                    isidentity  = Utils.Converter.ObjToBool("is_identity"),
                    filedtype   = fieldtype
                });
            }
            return(columns);
        }
Пример #2
0
 public void ToLocalTable(STable other, List <SqlToSqlModel> sqltypemodel, bool autofieldtypechange)
 {
     foreach (var a in other.columns)
     {
         foreach (var b in sqltypemodel)
         {
             if (a.filedtype.name == b.typename1)
             {
                 a.filedtype = DbFieldTypeHelper.SqlServerGetFieldType(b.typename2, a.filedtype.precision, a.filedtype.scale, a.filedtype.maxlength);
                 break;
             }
         }
         throw new Exception(a.filedtype.name + "不存在转化");
     }
 }
Пример #3
0
        public void ToLocalTable(STable other, List <SqlToSqlModel> sqltypemodel, bool autofieldtypechange)
        {
            foreach (var a in other.columns)
            {
                bool exist = false;
                foreach (var b in sqltypemodel)
                {
                    if (a.filedtype.name == b.typename1)
                    {
                        a.filedtype = DbFieldTypeHelper.MySqlGetFieldType(other.name, a.name, b.typename2, a.filedtype.precision, a.filedtype.scale, a.filedtype.maxlength, autofieldtypechange);
                        exist       = true;
                        break;
                    }
                }
                if (!exist)
                {
                    throw new Exception(a.filedtype.name + "不存在转化");
                }
            }
            List <DbStructure.SIndex> removeindexes = new List <SIndex>();

            for (int i = 0; i < other.indexes.Count; i++)
            {
                for (int j = i + 1; j < other.indexes.Count; j++)
                {
                    bool rowissame = true;
                    if (other.indexes[i].columns.Count == other.indexes[j].columns.Count)
                    {
                        foreach (var a in other.indexes[i].columns)
                        {
                            if (!other.indexes[j].columns.ContainsKey(a.Key))
                            {
                                rowissame = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        rowissame = false;
                    }
                    if (rowissame)
                    {
                        if (other.indexes[j].isprimarykey || other.indexes[j].isunique)
                        {
                            if (!removeindexes.Contains(other.indexes[i]))
                            {
                                removeindexes.Add(other.indexes[i]);
                            }
                        }
                        else
                        {
                            if (!removeindexes.Contains(other.indexes[j]))
                            {
                                removeindexes.Add(other.indexes[j]);
                            }
                        }
                    }
                }
            }
            foreach (var a in removeindexes)
            {
                other.indexes.Remove(a);
            }
        }