mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 增加 .Net Framework 4.0 的支持,出于环境考虑 .Net Framework 4.0 不支持异步方法;
- 增加 IFreeSql.Insert<T>(IEnumerable<T1> source) 方法;
This commit is contained in:
		@@ -53,6 +53,9 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            this.ClearData();
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if net40
 | 
			
		||||
#else
 | 
			
		||||
        async public override Task<List<T1>> ExecuteDeletedAsync()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
@@ -91,5 +94,6 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            this.ClearData();
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,12 +17,8 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int ExecuteAffrows() => base.SplitExecuteAffrows(5000, 3000);
 | 
			
		||||
        public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(5000, 3000);
 | 
			
		||||
        public override long ExecuteIdentity() => base.SplitExecuteIdentity(5000, 3000);
 | 
			
		||||
        public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(5000, 3000);
 | 
			
		||||
        public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(5000, 3000);
 | 
			
		||||
        public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(5000, 3000);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        protected override long RawExecuteIdentity()
 | 
			
		||||
        {
 | 
			
		||||
@@ -73,6 +69,50 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override List<T1> RawExecuteInserted()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
            if (string.IsNullOrEmpty(sql)) return new List<T1>();
 | 
			
		||||
 | 
			
		||||
            var sb = new StringBuilder();
 | 
			
		||||
            sb.Append(sql).Append(" RETURNING ");
 | 
			
		||||
 | 
			
		||||
            var colidx = 0;
 | 
			
		||||
            foreach (var col in _table.Columns.Values)
 | 
			
		||||
            {
 | 
			
		||||
                if (colidx > 0) sb.Append(", ");
 | 
			
		||||
                sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
 | 
			
		||||
                ++colidx;
 | 
			
		||||
            }
 | 
			
		||||
            sql = sb.ToString();
 | 
			
		||||
            var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
 | 
			
		||||
            _orm.Aop.CurdBefore?.Invoke(this, before);
 | 
			
		||||
            var ret = new List<T1>();
 | 
			
		||||
            Exception exception = null;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                exception = ex;
 | 
			
		||||
                throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                var after = new Aop.CurdAfterEventArgs(before, exception, ret);
 | 
			
		||||
                _orm.Aop.CurdAfter?.Invoke(this, after);
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if net40
 | 
			
		||||
#else
 | 
			
		||||
        public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(5000, 3000);
 | 
			
		||||
        public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(5000, 3000);
 | 
			
		||||
        public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(5000, 3000);
 | 
			
		||||
        
 | 
			
		||||
        async protected override Task<long> RawExecuteIdentityAsync()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
@@ -122,43 +162,6 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override List<T1> RawExecuteInserted()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
            if (string.IsNullOrEmpty(sql)) return new List<T1>();
 | 
			
		||||
 | 
			
		||||
            var sb = new StringBuilder();
 | 
			
		||||
            sb.Append(sql).Append(" RETURNING ");
 | 
			
		||||
 | 
			
		||||
            var colidx = 0;
 | 
			
		||||
            foreach (var col in _table.Columns.Values)
 | 
			
		||||
            {
 | 
			
		||||
                if (colidx > 0) sb.Append(", ");
 | 
			
		||||
                sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
 | 
			
		||||
                ++colidx;
 | 
			
		||||
            }
 | 
			
		||||
            sql = sb.ToString();
 | 
			
		||||
            var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params);
 | 
			
		||||
            _orm.Aop.CurdBefore?.Invoke(this, before);
 | 
			
		||||
            var ret = new List<T1>();
 | 
			
		||||
            Exception exception = null;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _params);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                exception = ex;
 | 
			
		||||
                throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                var after = new Aop.CurdAfterEventArgs(before, exception, ret);
 | 
			
		||||
                _orm.Aop.CurdAfter?.Invoke(this, after);
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
        async protected override Task<List<T1>> RawExecuteInsertedAsync()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
@@ -195,5 +198,6 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,10 +19,7 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int ExecuteAffrows() => base.SplitExecuteAffrows(500, 3000);
 | 
			
		||||
        public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(500, 3000);
 | 
			
		||||
        public override List<T1> ExecuteUpdated() => base.SplitExecuteUpdated(500, 3000);
 | 
			
		||||
        public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(500, 3000);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        protected override List<T1> RawExecuteUpdated()
 | 
			
		||||
        {
 | 
			
		||||
@@ -62,44 +59,6 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
        async protected override Task<List<T1>> RawExecuteUpdatedAsync()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
            if (string.IsNullOrEmpty(sql)) return new List<T1>();
 | 
			
		||||
 | 
			
		||||
            var sb = new StringBuilder();
 | 
			
		||||
            sb.Append(sql).Append(" RETURNING ");
 | 
			
		||||
 | 
			
		||||
            var colidx = 0;
 | 
			
		||||
            foreach (var col in _table.Columns.Values)
 | 
			
		||||
            {
 | 
			
		||||
                if (colidx > 0) sb.Append(", ");
 | 
			
		||||
                sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
 | 
			
		||||
                ++colidx;
 | 
			
		||||
            }
 | 
			
		||||
            sql = sb.ToString();
 | 
			
		||||
            var dbParms = _params.Concat(_paramsSource).ToArray();
 | 
			
		||||
            var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Update, sql, dbParms);
 | 
			
		||||
            _orm.Aop.CurdBefore?.Invoke(this, before);
 | 
			
		||||
            var ret = new List<T1>();
 | 
			
		||||
            Exception exception = null;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
 | 
			
		||||
                ValidateVersionAndThrow(ret.Count);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                exception = ex;
 | 
			
		||||
                throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                var after = new Aop.CurdAfterEventArgs(before, exception, ret);
 | 
			
		||||
                _orm.Aop.CurdAfter?.Invoke(this, after);
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys)
 | 
			
		||||
        {
 | 
			
		||||
@@ -145,5 +104,50 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
 | 
			
		||||
            sb.Append("::").Append(dbtype);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if net40
 | 
			
		||||
#else
 | 
			
		||||
        public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(500, 3000);
 | 
			
		||||
        public override Task<List<T1>> ExecuteUpdatedAsync() => base.SplitExecuteUpdatedAsync(500, 3000);
 | 
			
		||||
        
 | 
			
		||||
        async protected override Task<List<T1>> RawExecuteUpdatedAsync()
 | 
			
		||||
        {
 | 
			
		||||
            var sql = this.ToSql();
 | 
			
		||||
            if (string.IsNullOrEmpty(sql)) return new List<T1>();
 | 
			
		||||
 | 
			
		||||
            var sb = new StringBuilder();
 | 
			
		||||
            sb.Append(sql).Append(" RETURNING ");
 | 
			
		||||
 | 
			
		||||
            var colidx = 0;
 | 
			
		||||
            foreach (var col in _table.Columns.Values)
 | 
			
		||||
            {
 | 
			
		||||
                if (colidx > 0) sb.Append(", ");
 | 
			
		||||
                sb.Append(_commonUtils.QuoteReadColumn(col.Attribute.MapType, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
 | 
			
		||||
                ++colidx;
 | 
			
		||||
            }
 | 
			
		||||
            sql = sb.ToString();
 | 
			
		||||
            var dbParms = _params.Concat(_paramsSource).ToArray();
 | 
			
		||||
            var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Update, sql, dbParms);
 | 
			
		||||
            _orm.Aop.CurdBefore?.Invoke(this, before);
 | 
			
		||||
            var ret = new List<T1>();
 | 
			
		||||
            Exception exception = null;
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, dbParms);
 | 
			
		||||
                ValidateVersionAndThrow(ret.Count);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                exception = ex;
 | 
			
		||||
                throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                var after = new Aop.CurdAfterEventArgs(before, exception, ret);
 | 
			
		||||
                _orm.Aop.CurdAfter?.Invoke(this, after);
 | 
			
		||||
            }
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -150,6 +150,8 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if net40
 | 
			
		||||
#else
 | 
			
		||||
        async public Task OnGetAsync(Object<DbConnection> obj)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
@@ -177,6 +179,7 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        public void OnGetTimeout()
 | 
			
		||||
        {
 | 
			
		||||
@@ -223,6 +226,9 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if net40
 | 
			
		||||
#else
 | 
			
		||||
        async public static Task<bool> PingAsync(this DbConnection that, bool isThrow = false)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
@@ -237,5 +243,6 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,11 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
            if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new (OdbcType, string, string, bool?, object)?((trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue));
 | 
			
		||||
            if (type.IsArray) return null;
 | 
			
		||||
            var enumType = type.IsEnum ? type : null;
 | 
			
		||||
            if (enumType == null && type.IsNullableType() && type.GenericTypeArguments.Length == 1 && type.GenericTypeArguments.First().IsEnum) enumType = type.GenericTypeArguments.First();
 | 
			
		||||
            if (enumType == null && type.IsNullableType())
 | 
			
		||||
            {
 | 
			
		||||
                var genericTypes = type.GetGenericArguments();
 | 
			
		||||
                if (genericTypes.Length == 1 && genericTypes.First().IsEnum) enumType = genericTypes.First();
 | 
			
		||||
            }
 | 
			
		||||
            if (enumType != null)
 | 
			
		||||
            {
 | 
			
		||||
                var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?
 | 
			
		||||
 
 | 
			
		||||
@@ -465,7 +465,7 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
                    case "AddTicks": return $"(({left})::timestamp+(({args1})/10||' microseconds')::interval)";
 | 
			
		||||
                    case "AddYears": return $"(({left})::timestamp+(({args1})||' year')::interval)";
 | 
			
		||||
                    case "Subtract":
 | 
			
		||||
                        switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault() : exp.Arguments[0].Type).FullName)
 | 
			
		||||
                        switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName)
 | 
			
		||||
                        {
 | 
			
		||||
                            case "System.DateTime": return $"(extract(epoch from ({left})::timestamp-({args1})::timestamp)*1000000)";
 | 
			
		||||
                            case "System.TimeSpan": return $"(({left})::timestamp-(({args1})||' microseconds')::interval)";
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
        public IInsert<T1> Insert<T1>(T1 source) where T1 : class => this.Insert<T1>().AppendData(source);
 | 
			
		||||
        public IInsert<T1> Insert<T1>(T1[] source) where T1 : class => this.Insert<T1>().AppendData(source);
 | 
			
		||||
        public IInsert<T1> Insert<T1>(List<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
 | 
			
		||||
        public IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class => this.Insert<T1>().AppendData(source);
 | 
			
		||||
        public IUpdate<T1> Update<T1>() where T1 : class => new OdbcPostgreSQLUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
 | 
			
		||||
        public IUpdate<T1> Update<T1>(object dywhere) where T1 : class => new OdbcPostgreSQLUpdate<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere);
 | 
			
		||||
        public IDelete<T1> Delete<T1>() where T1 : class => new OdbcPostgreSQLDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, null);
 | 
			
		||||
 
 | 
			
		||||
@@ -47,13 +47,17 @@ namespace FreeSql.Odbc.PostgreSQL
 | 
			
		||||
                var elementType = type.GetElementType();
 | 
			
		||||
                Type enumType = null;
 | 
			
		||||
                if (elementType.IsEnum) enumType = elementType;
 | 
			
		||||
                else if (elementType.IsNullableType() && elementType.GenericTypeArguments.First().IsEnum) enumType = elementType.GenericTypeArguments.First();
 | 
			
		||||
                else if (elementType.IsNullableType())
 | 
			
		||||
                {
 | 
			
		||||
                    var genericTypesFirst = elementType.GetGenericArguments().First();
 | 
			
		||||
                    if (genericTypesFirst.IsEnum) enumType = genericTypesFirst;
 | 
			
		||||
                }
 | 
			
		||||
                if (enumType != null) return enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?
 | 
			
		||||
                    getParamterArrayValue(typeof(long), value, elementType.IsEnum ? null : Enum.GetValues(enumType).GetValue(0)) :
 | 
			
		||||
                    getParamterArrayValue(typeof(int), value, elementType.IsEnum ? null : Enum.GetValues(enumType).GetValue(0));
 | 
			
		||||
                return dicGetParamterValue.TryGetValue(type.FullName, out var trydicarr) ? trydicarr(value) : value;
 | 
			
		||||
            }
 | 
			
		||||
            if (type.IsNullableType()) type = type.GenericTypeArguments.First();
 | 
			
		||||
            if (type.IsNullableType()) type = type.GetGenericArguments().First();
 | 
			
		||||
            if (type.IsEnum) return (int)value;
 | 
			
		||||
            if (dicGetParamterValue.TryGetValue(type.FullName, out var trydic)) return trydic(value);
 | 
			
		||||
            return value;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user