SetColumnDbType() 정적인 개인적인 메소드

static private SetColumnDbType ( DBAdapter dbAdapter, Attribute info, string>.Dictionary dic ) : void
dbAdapter DBAdapter
info System.Attribute
dic string>.Dictionary
리턴 void
예제 #1
0
        //static Dictionary<string, List<string>> tableCache = new Dictionary<string, List<string>>();
        /// <summary>
        /// 检查表是否被创建
        /// </summary>
        internal void CheckTableCreated(Type type)
        {
            TypeCache.SetDBAdapterCache(type, _DBAdapter);
            var dbName        = helper.DatabaseName;
            var cacheInstance = ExistsTableCache.Instance;
            var table         = TypeCache.GetTable(type);

            if (!cacheInstance.Tables.ContainsKey(dbName))
            {
                #region 初始表
                lock (lockObj)
                {
                    BackupParams();
                    string sql = _DBAdapter.GetAllTablesSql(helper);
                    var    dic = ExecDictionary <string, int>(sql);
                    RecoveryParams();
                    cacheInstance.InitTable(dbName, dic.Keys.ToList());
                }
                #endregion
            }
            var tb = cacheInstance.GetTable(dbName, table);
            if (tb == null)//没有创建表
            {
                #region 创建表
                BackupParams();
                var    obj = System.Activator.CreateInstance(type) as IModel;
                string msg;
                var    a = obj.CreateTable(this, out msg);
                RecoveryParams();
                if (!a)
                {
                    return;

                    throw new Exception(msg);
                }
                cacheInstance.SaveTable(dbName, table);
                return;

                #endregion
            }
            if (tb.ColumnChecked)
            {
                return;
            }
            //判断字段是否一致
            var needCreates = ExistsTableCache.Instance.CheckFieldExists(dbName, table);
            if (needCreates.Count > 0)
            {
                #region 创建列
                BackupParams();
                var mapping = _DBAdapter.GetFieldMapping();
                foreach (var item in needCreates)
                {
                    IModel.SetColumnDbType(_DBAdapter, item, mapping);
                    string str = IModel.CreateColumn(this, item);
                }
                RecoveryParams();
                #endregion
            }
        }
예제 #2
0
        //static Dictionary<string, List<string>> tableCache = new Dictionary<string, List<string>>();
        /// <summary>
        /// 检查表是否被创建
        /// </summary>
        internal void CheckTableCreated(Type type)
        {
            if (!SettingConfig.CheckModelTableMaping)
            {
                return;
            }
            //TypeCache.SetDBAdapterCache(type, _DBAdapter);
            var      dbName        = dbHelper.DatabaseName;
            var      cacheInstance = CRL.ExistsTableCache.ExistsTableCache.Instance;
            var      table         = TypeCache.GetTable(type);
            DBExtend db;

            if (cacheInstance.DataBase.Find(b => b.Name == dbName) == null)
            {
                db = GetBackgroundDBExtend();
                #region 初始表
                lock (lockObj)
                {
                    //BackupParams();
                    string sql = _DBAdapter.GetAllTablesSql();
                    var    dic = db.ExecDictionary <string, int>(sql);
                    //RecoveryParams();
                    cacheInstance.InitTable(dbName, dic.Keys.ToList());
                }
                #endregion
            }
            var tableName = TypeCache.GetTableName(table.TableName, dbContext);
            var tb        = cacheInstance.GetTable(dbName, tableName);
            if (tb == null)//没有创建表
            {
                db = GetBackgroundDBExtend();
                #region 创建表
                //BackupParams();
                var obj       = System.Activator.CreateInstance(type) as IModel;
                var initDatas = obj.GetInitData();
                if (initDatas != null)
                {
                    foreach (IModel item in initDatas)
                    {
                        CheckData(item);
                    }
                }
                string msg;
                var    a = obj.CreateTable(db, out msg);
                //RecoveryParams();
                if (!a)
                {
                    return;

                    throw new Exception(msg);
                }
                cacheInstance.SaveTable(dbName, table, tableName);
                if (initDatas != null)
                {
                    _DBAdapter.BatchInsert(initDatas, false);
                }
                return;

                #endregion
            }
            if (tb.ColumnChecked)
            {
                return;
            }
            //判断字段是否一致
            var needCreates = CRL.ExistsTableCache.ExistsTableCache.Instance.CheckFieldExists(dbName, table, tableName);
            if (needCreates.Count > 0)
            {
                db = GetBackgroundDBExtend();
                #region 创建列
                //BackupParams();
                foreach (var item in needCreates)
                {
                    IModel.SetColumnDbType(_DBAdapter, item);
                    string str = IModel.CreateColumn(db, item);
                }
                //RecoveryParams();
                #endregion
            }
            //二次检查,对照表结构
            if (!tb.ColumnChecked2)
            {
                db = GetBackgroundDBExtend();
                ExistsTableCache.ColumnBackgroundCheck.Add(db, type);
                tb.ColumnChecked2 = true;
            }
        }