//private const string SqlClient = "System.Data.SqlClient"; //private const string OleDb = "System.Data.OleDb"; //private const string OracleClient = "System.Data.OracleClient"; //private const string SQLiteClient = "System.Data.SQLite"; //private const string MySqlClient = "MySql.Data.MySqlClient"; //private const string SybaseClient = "Sybase.Data.AseClient"; //private const string PostgreClient = "System.Data.NpgSqlClient"; //private const string TxtClient = "CYQ.Data.TxtClient"; //private const string XmlClient = "CYQ.Data.XmlClient"; //private const string XHtmlClient = "CYQ.Data.XHtmlClient"; /// <summary> /// ¼òµ¥¹¤³§£¨Factory Method£© /// </summary> /// <param name="dbConn"></param> /// <returns></returns> public static DbBase CreateDal(string connNameOrString) { //ABCConn DbBase db = GetDbBaseBy(ConnObject.Create(connNameOrString)); if (db.connObject.Master.ConnName != connNameOrString && connNameOrString.EndsWith("Conn"))//ÐèÒªÇл»ÅäÖᣠ{ //Conn A¿â //BConn xxx ÕÒ²»µ½Ê±£¬ÕÒĬÈÏ¿â¡£ DbResetResult result = db.ChangeDatabase(connNameOrString.Substring(0, connNameOrString.Length - 4)); if (result == DbResetResult.Yes) // дÈ뻺´æ { db.connObject.SaveToCache(connNameOrString); } } return(db); }
/// <summary> /// 简单工厂(Factory Method) /// </summary> /// <param name="dbConn"></param> /// <returns></returns> public static DbBase CreateDal(string dbConn) { DbBase db = GetDbBaseBy(GetConnObject(dbConn)); if (db.connObject.Master.ConfigName != dbConn && dbConn.EndsWith("Conn"))//需要切换配置。 { DbResetResult result = db.ChangeDatabase(dbConn.Substring(0, dbConn.Length - 4)); if (result == DbResetResult.Yes) // 写入缓存 { if (!connDicCache.ContainsKey(dbConn)) { connDicCache.Set(dbConn, db.connObject); } } } return(db); //ConnEntity cEntity = GetConnString(dbConn); //DbBase db = GetDbBaseBy(cEntity.Conn, cEntity.ProviderName); //db.connObject = cEntity; //return db; }
/// <summary> /// 获取表列架构(链接错误时,抛异常) /// </summary> /// <param name="tableName">表名</param> /// <param name="conn">数据库链接</param> /// <param name="errInfo">出错时的错误信息</param> /// <returns></returns> public static MDataColumn GetColumns(string tableName, string conn, out string errInfo) { errInfo = string.Empty; DbBase helper = DalCreate.CreateDal(conn); DbResetResult result = helper.ChangeDatabaseWithCheck(tableName);//检测dbname.dbo.tablename的情况 switch (result) { case DbResetResult.No_DBNoExists: helper.Dispose(); return(null); case DbResetResult.No_SaveDbName: case DbResetResult.Yes: tableName = SqlFormat.NotKeyword(tableName); //same database no need database.tablename break; } if (!helper.TestConn(AllowConnLevel.MaterBackupSlave)) { errInfo = helper.debugInfo.ToString(); if (string.IsNullOrEmpty(errInfo)) { errInfo = "Open database fail : " + tableName; } helper.Dispose(); Error.Throw(errInfo); return(null); } if (!tableName.Contains(" "))// { tableName = GetMapTableName(conn, tableName); } MDataColumn mdc = TableSchema.GetColumns(tableName, ref helper); helper.Dispose(); return(mdc); }