Пример #1
0
 public static bool Remove(string name, string type, string conn)
 {
     if (!string.IsNullOrEmpty(name) && DBSchema.DBScheams.Count > 0)
     {
         int tableHash = TableSchema.GetTableHash(name);
         Dictionary <string, string> dic = TableSchema.GetSchemas(conn, type);
         if (dic != null && dic.ContainsKey(name))
         {
             dic.Remove(name);
         }
         if (!string.IsNullOrEmpty(conn))
         {
             int dbHash = ConnBean.GetHashCode(conn);
             if (DBSchema.DBScheams.ContainsKey(dbHash))
             {
                 return(DBSchema.DBScheams[dbHash].Remove(tableHash, type));
             }
         }
         else
         {
             foreach (KeyValuePair <int, DBInfo> item in DBSchema.DBScheams)
             {
                 if (item.Value.Remove(tableHash, type))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Пример #2
0
 /// <summary>
 /// 获得数据库表相关信息
 /// </summary>
 /// <param name="conn">指定时优先寻找。</param>
 /// <param name="name">表名</param>
 /// <returns></returns>
 public static TableInfo GetTableInfoByName(string name, string conn)
 {
     if (!string.IsNullOrEmpty(name) && DBSchema.DBScheams.Count > 0)
     {
         int tableHash = TableSchema.GetTableHash(name);
         if (!string.IsNullOrEmpty(conn))
         {
             int dbHash = ConnBean.GetHashCode(conn);
             if (DBSchema.DBScheams.ContainsKey(dbHash))
             {
                 TableInfo info = DBSchema.DBScheams[dbHash].GetTableInfo(tableHash);
                 if (info != null)
                 {
                     return(info);
                 }
             }
         }
         foreach (KeyValuePair <int, DBInfo> item in DBSchema.DBScheams)
         {
             TableInfo info = item.Value.GetTableInfo(tableHash);
             if (info != null)
             {
                 return(info);
             }
         }
     }
     return(null);
 }
Пример #3
0
 /// <summary>
 /// 是否存在指定的表名、视图名、存储过程名
 /// </summary>
 /// <param name="name"></param>
 /// <param name="conn"></param>
 /// <returns></returns>
 public static bool Exists(string name, string type, string conn)
 {
     if (!string.IsNullOrEmpty(name) && DBSchema.DBScheams.Count > 0)
     {
         int tableHash = TableSchema.GetTableHash(name);
         if (!string.IsNullOrEmpty(conn))
         {
             int dbHash = ConnBean.GetHashCode(conn);
             if (DBSchema.DBScheams.ContainsKey(dbHash))
             {
                 TableInfo info = DBSchema.DBScheams[dbHash].GetTableInfo(tableHash, type);
                 if (info != null)
                 {
                     return(true);
                 }
             }
         }
         else
         {
             foreach (KeyValuePair <int, DBInfo> item in DBSchema.DBScheams)
             {
                 TableInfo info = item.Value.GetTableInfo(tableHash, type);
                 if (info != null)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Пример #4
0
        private static DBInfo GetSchemaDic(string conn)
        {
            DalBase dal = DalCreate.CreateDal(conn);

            DBInfo info = new DBInfo();

            info.ConnName     = dal.ConnObj.Master.ConnName;
            info.ConnString   = dal.ConnObj.Master.ConnString;
            info.DataBaseName = dal.DataBase;
            Dictionary <string, string> tables = TableSchema.GetTables(conn);

            if (tables != null && tables.Count > 0)
            {
                Dictionary <int, TableInfo> dic = new Dictionary <int, TableInfo>();
                foreach (KeyValuePair <string, string> item in tables)
                {
                    dic.Add(TableSchema.GetTableHash(item.Key), new TableInfo(item.Key, "U", item.Value, info));
                }
                info.Tables = dic;
            }

            Dictionary <string, string> views = TableSchema.GetViews(conn);

            if (views != null && views.Count > 0)
            {
                Dictionary <int, TableInfo> dic = new Dictionary <int, TableInfo>();
                foreach (KeyValuePair <string, string> item in views)
                {
                    dic.Add(TableSchema.GetTableHash(item.Key), new TableInfo(item.Key, "V", item.Value, info));
                }
                info.Views = dic;
            }
            Dictionary <string, string> procs = TableSchema.GetProcs(conn);

            if (procs != null && procs.Count > 0)
            {
                Dictionary <int, TableInfo> dic = new Dictionary <int, TableInfo>();
                foreach (KeyValuePair <string, string> item in procs)
                {
                    dic.Add(TableSchema.GetTableHash(item.Key), new TableInfo(item.Key, "P", item.Value, info));
                }
                info.Procs = dic;
            }
            return(info);
        }
Пример #5
0
 public static bool Add(string name, string type, string conn)
 {
     if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(type) && DBSchema.DBScheams.Count > 0)
     {
         int tableHash = TableSchema.GetTableHash(name);
         Dictionary <string, string> dic = TableSchema.GetSchemas(conn, type);
         if (dic != null && !dic.ContainsKey(name))
         {
             dic.Add(name, name);
         }
         int dbHash = ConnBean.GetHashCode(conn);
         if (DBSchema.DBScheams.ContainsKey(dbHash))
         {
             return(DBSchema.DBScheams[dbHash].Add(tableHash, type, name));
         }
     }
     return(false);
 }