Beispiel #1
0
        /// <summary>
        /// 是否存在指定的表名、视图名、存储过程名
        /// </summary>
        /// <param name="newName"></param>
        /// <param name="conn"></param>
        /// <returns></returns>
        public static bool Exists(string name, string type, string conn)
        {
            string newName = name;
            string newConn = GetConn(newName, out newName, conn);

            if (string.IsNullOrEmpty(conn) || (name.Contains("..") && newConn.StartsWith(name.Split('.')[0])))//已指定链接,则不切换链接
            {
                conn = newConn;
            }
            //if (DBSchema.DBScheams.Count == 0 && !string.IsNullOrEmpty(conn))
            //{
            //    DBSchema.GetSchema(conn);
            //}
            if (!string.IsNullOrEmpty(newName))// && DBSchema.DBScheams.Count > 0
            {
                string tableHash = TableInfo.GetHashKey(newName);
                if (!string.IsNullOrEmpty(conn))
                {
                    string dbHash = ConnBean.GetHashKey(conn);
                    if (DBSchema.DBScheams.ContainsKey(dbHash))
                    {
                        TableInfo info = DBSchema.DBScheams[dbHash].GetTableInfo(tableHash, type);
                        if (info != null)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        DBInfo dbInfo = DBSchema.GetSchema(conn, false);
                        if (dbInfo != null)
                        {
                            TableInfo info = dbInfo.GetTableInfo(tableHash, type);
                            if (info != null)
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, DBInfo> item in DBSchema.DBScheams)
                    {
                        TableInfo info = item.Value.GetTableInfo(tableHash, type);
                        if (info != null)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #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))
     {
         name = SqlFormat.NotKeyword(name);
         string tableHash = TableInfo.GetHashKey(name);
         if (!string.IsNullOrEmpty(conn))
         {
             string dbHash = ConnBean.GetHashKey(conn);
             if (DBSchema.DBScheams.Count > 0 && DBSchema.DBScheams.ContainsKey(dbHash))
             {
                 TableInfo info = DBSchema.DBScheams[dbHash].GetTableInfo(tableHash);
                 if (info != null)
                 {
                     return(info);
                 }
             }
             else
             {
                 DBInfo dbInfo = DBSchema.GetSchema(conn, false);
                 if (dbInfo != null)
                 {
                     TableInfo info = dbInfo.GetTableInfo(tableHash);
                     if (info != null)
                     {
                         return(info);
                     }
                 }
             }
         }
         else
         {
             DBInfo dbInfo = DBSchema.GetSchema(AppConfig.DB.DefaultConn, false);//优先取默认链接
             if (dbInfo != null)
             {
                 TableInfo info = dbInfo.GetTableInfo(tableHash);
                 if (info != null)
                 {
                     return(info);
                 }
             }
         }
         foreach (KeyValuePair <string, DBInfo> item in DBSchema.DBScheams)
         {
             TableInfo info = item.Value.GetTableInfo(tableHash);
             if (info != null)
             {
                 return(info);
             }
         }
     }
     return(null);
 }
Beispiel #3
0
 /// <summary>
 /// 是否存在指定的表名、视图名、存储过程名
 /// </summary>
 /// <param name="name"></param>
 /// <param name="conn"></param>
 /// <returns></returns>
 public static bool Exists(string name, string type, string conn)
 {
     conn = GetConn(name, out name, conn);
     if (DBSchema.DBScheams.Count == 0 && !string.IsNullOrEmpty(conn))
     {
         DBSchema.GetSchema(conn);
     }
     if (!string.IsNullOrEmpty(name) && DBSchema.DBScheams.Count > 0)
     {
         int tableHash = TableInfo.GetHashCode(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
             {
                 DBInfo dbInfo = DBSchema.GetSchema(conn);
                 if (dbInfo != null)
                 {
                     TableInfo info = dbInfo.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);
 }
Beispiel #4
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))
     {
         name = SqlFormat.NotKeyword(name);
         int tableHash = TableInfo.GetHashCode(name);
         if (!string.IsNullOrEmpty(conn))
         {
             int dbHash = ConnBean.GetHashCode(conn);
             if (DBSchema.DBScheams.Count > 0 && DBSchema.DBScheams.ContainsKey(dbHash))
             {
                 TableInfo info = DBSchema.DBScheams[dbHash].GetTableInfo(tableHash);
                 if (info != null)
                 {
                     return(info);
                 }
             }
             else
             {
                 DBInfo dbInfo = DBSchema.GetSchema(conn);
                 if (dbInfo != null)
                 {
                     TableInfo info = dbInfo.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);
 }