mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 增加 Where In 表达式解析;
- 增加 FreeSqlBuilder.UseConnectionFactory 自定义数据库连接对象的创建方法;
This commit is contained in:
		@@ -12,10 +12,15 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
{
 | 
			
		||||
    class OdbcDamengAdo : FreeSql.Internal.CommonProvider.AdoProvider
 | 
			
		||||
    {
 | 
			
		||||
        public OdbcDamengAdo() : base(DataType.Oracle) { }
 | 
			
		||||
        public OdbcDamengAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings) : base(DataType.Oracle)
 | 
			
		||||
        public OdbcDamengAdo() : base(DataType.OdbcDameng) { }
 | 
			
		||||
        public OdbcDamengAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func<DbConnection> connectionFactory) : base(DataType.OdbcDameng)
 | 
			
		||||
        {
 | 
			
		||||
            base._util = util;
 | 
			
		||||
            if (connectionFactory != null)
 | 
			
		||||
            {
 | 
			
		||||
                MasterPool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcDameng, connectionFactory);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if (!string.IsNullOrEmpty(masterConnectionString))
 | 
			
		||||
                MasterPool = new OdbcDamengConnectionPool("主库", masterConnectionString, null, null);
 | 
			
		||||
            if (slaveConnectionStrings != null)
 | 
			
		||||
@@ -57,9 +62,11 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
            return new OdbcCommand();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void ReturnConnection(ObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
 | 
			
		||||
        protected override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            (pool as OdbcDamengConnectionPool).Return(conn, ex);
 | 
			
		||||
            var rawPool = pool as OdbcDamengConnectionPool;
 | 
			
		||||
            if (rawPool != null) rawPool.Return(conn, ex);
 | 
			
		||||
            else pool.Return(conn);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,7 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
 | 
			
		||||
        public OdbcDamengConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null)
 | 
			
		||||
        {
 | 
			
		||||
            var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
 | 
			
		||||
            if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
 | 
			
		||||
            this.UserId = userIdMatch.Groups[2].Value.Trim().ToUpper();
 | 
			
		||||
            this.UserId = OdbcDamengConnectionPool.GetUserId(connectionString);
 | 
			
		||||
 | 
			
		||||
            var policy = new OdbcOracleConnectionPoolPolicy
 | 
			
		||||
            {
 | 
			
		||||
@@ -37,6 +35,13 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
            this.unavailableHandler = unavailableHandler;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string GetUserId(string connectionString)
 | 
			
		||||
        {
 | 
			
		||||
            var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase);
 | 
			
		||||
            if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)");
 | 
			
		||||
            return userIdMatch.Groups[2].Value.Trim().ToUpper();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Return(Object<DbConnection> obj, Exception exception, bool isRecreate = false)
 | 
			
		||||
        {
 | 
			
		||||
            if (exception != null && exception is OdbcException)
 | 
			
		||||
 
 | 
			
		||||
@@ -77,7 +77,12 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
 | 
			
		||||
        protected override string GetComparisonDDLStatements(params (Type entityType, string tableName)[] objects)
 | 
			
		||||
        {
 | 
			
		||||
            var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool).UserId;
 | 
			
		||||
            var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool)?.UserId;
 | 
			
		||||
            if (string.IsNullOrEmpty(userId))
 | 
			
		||||
                using (var conn = _orm.Ado.MasterPool.Get())
 | 
			
		||||
                {
 | 
			
		||||
                    userId = OdbcDamengConnectionPool.GetUserId(conn.Value.ConnectionString);
 | 
			
		||||
                }
 | 
			
		||||
            var seqcols = new List<(ColumnInfo, string[], bool)>(); //序列:列,表,自增
 | 
			
		||||
            var seqnameDel = new List<string>(); //要删除的序列+触发器
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,12 +28,12 @@ namespace FreeSql.Odbc.Dameng
 | 
			
		||||
        public IAop Aop { get; }
 | 
			
		||||
        public ICodeFirst CodeFirst { get; }
 | 
			
		||||
        public IDbFirst DbFirst { get; }
 | 
			
		||||
        public OdbcDamengProvider(string masterConnectionString, string[] slaveConnectionString)
 | 
			
		||||
        public OdbcDamengProvider(string masterConnectionString, string[] slaveConnectionString, Func<DbConnection> connectionFactory = null)
 | 
			
		||||
        {
 | 
			
		||||
            this.InternalCommonUtils = new OdbcDamengUtils(this);
 | 
			
		||||
            this.InternalCommonExpression = new OdbcDamengExpression(this.InternalCommonUtils);
 | 
			
		||||
 | 
			
		||||
            this.Ado = new OdbcDamengAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString);
 | 
			
		||||
            this.Ado = new OdbcDamengAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory);
 | 
			
		||||
            this.Aop = new AopProvider();
 | 
			
		||||
 | 
			
		||||
            this.DbFirst = new OdbcDamengDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user