mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 增加 FreeSql.Provider.Dameng 基于 DmProvider Ado.net 访问达梦数据库;#155
This commit is contained in:
		@@ -803,7 +803,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
                    var propGetSetMethod = prop.GetSetMethod(true);
 | 
			
		||||
                    Expression readExpAssign = null; //加速缓存
 | 
			
		||||
                    if (prop.PropertyType.IsArray) readExpAssign = Expression.New(Utils.RowInfo.Constructor,
 | 
			
		||||
                        Utils.GetDataReaderValueBlockExpression(prop.PropertyType, Expression.Call(rowExp, Utils.MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                        Utils.GetDataReaderValueBlockExpression(prop.PropertyType, Expression.Call(Utils.MethodDataReaderGetValue, new Expression[] { Expression.Constant(_commonUtils), rowExp, dataIndexExp })),
 | 
			
		||||
                        //Expression.Call(Utils.MethodGetDataReaderValue, new Expression[] { Expression.Constant(prop.PropertyType), Expression.Call(rowExp, Utils.MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                        Expression.Add(dataIndexExp, Expression.Constant(1))
 | 
			
		||||
                    );
 | 
			
		||||
@@ -813,7 +813,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
                        if (proptypeGeneric.IsNullableType()) proptypeGeneric = proptypeGeneric.GetGenericArguments().First();
 | 
			
		||||
                        if (proptypeGeneric.IsEnum ||
 | 
			
		||||
                            Utils.dicExecuteArrayRowReadClassOrTuple.ContainsKey(proptypeGeneric)) readExpAssign = Expression.New(Utils.RowInfo.Constructor,
 | 
			
		||||
                                Utils.GetDataReaderValueBlockExpression(prop.PropertyType, Expression.Call(rowExp, Utils.MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                                Utils.GetDataReaderValueBlockExpression(prop.PropertyType, Expression.Call(Utils.MethodDataReaderGetValue, new Expression[] { Expression.Constant(_commonUtils), rowExp, dataIndexExp })),
 | 
			
		||||
                                //Expression.Call(Utils.MethodGetDataReaderValue, new Expression[] { Expression.Constant(prop.PropertyType), Expression.Call(rowExp, Utils.MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                                Expression.Add(dataIndexExp, Expression.Constant(1))
 | 
			
		||||
                        );
 | 
			
		||||
@@ -1069,6 +1069,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
			
		||||
                case DataType.Sqlite:
 | 
			
		||||
                    break;
 | 
			
		||||
                case DataType.OdbcDameng:
 | 
			
		||||
                case DataType.Dameng:
 | 
			
		||||
                    _tosqlAppendContent = $" for update{(noawait ? " nowait" : "")}";
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -1235,7 +1235,12 @@ namespace FreeSql.Internal
 | 
			
		||||
            public static PropertyInfo PropertyValue = typeof(RowInfo).GetProperty("Value");
 | 
			
		||||
            public static PropertyInfo PropertyDataIndex = typeof(RowInfo).GetProperty("DataIndex");
 | 
			
		||||
        }
 | 
			
		||||
        internal static MethodInfo MethodDataReaderGetValue = typeof(DbDataReader).GetMethod("GetValue");
 | 
			
		||||
        internal static MethodInfo MethodDataReaderGetValue = typeof(Utils).GetMethod("InternalDataReaderGetValue", BindingFlags.Static | BindingFlags.NonPublic);
 | 
			
		||||
        internal static object InternalDataReaderGetValue(CommonUtils commonUtil, DbDataReader dr, int index)
 | 
			
		||||
        {
 | 
			
		||||
            if (commonUtil._orm.Ado.DataType == DataType.Dameng && dr.IsDBNull(index)) return null;
 | 
			
		||||
            return dr.GetValue(index);
 | 
			
		||||
        }
 | 
			
		||||
        internal static RowInfo ExecuteArrayRowReadClassOrTuple(string flagStr, Type typeOrg, int[] indexes, DbDataReader row, int dataIndex, CommonUtils _commonUtils)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrEmpty(flagStr)) flagStr = "all";
 | 
			
		||||
@@ -1252,8 +1257,8 @@ namespace FreeSql.Internal
 | 
			
		||||
 | 
			
		||||
                    if (type.IsArray) return Expression.Lambda<Func<Type, int[], DbDataReader, int, CommonUtils, RowInfo>>(
 | 
			
		||||
                        Expression.New(RowInfo.Constructor,
 | 
			
		||||
                            GetDataReaderValueBlockExpression(type, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { typeExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                            GetDataReaderValueBlockExpression(type, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })),
 | 
			
		||||
                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { typeExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp }) }),
 | 
			
		||||
                            Expression.Add(dataIndexExp, Expression.Constant(1))
 | 
			
		||||
                        ), new[] { typeExp, indexesExp, rowExp, dataIndexExp, commonUtilExp }).Compile();
 | 
			
		||||
 | 
			
		||||
@@ -1263,8 +1268,8 @@ namespace FreeSql.Internal
 | 
			
		||||
                        dicExecuteArrayRowReadClassOrTuple.ContainsKey(typeGeneric))
 | 
			
		||||
                        return Expression.Lambda<Func<Type, int[], DbDataReader, int, CommonUtils, RowInfo>>(
 | 
			
		||||
                        Expression.New(RowInfo.Constructor,
 | 
			
		||||
                            GetDataReaderValueBlockExpression(type, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { typeExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                            GetDataReaderValueBlockExpression(type, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })),
 | 
			
		||||
                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { typeExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp }) }),
 | 
			
		||||
                            Expression.Add(dataIndexExp, Expression.Constant(1))
 | 
			
		||||
                        ), new[] { typeExp, indexesExp, rowExp, dataIndexExp, commonUtilExp }).Compile();
 | 
			
		||||
 | 
			
		||||
@@ -1284,8 +1289,8 @@ namespace FreeSql.Internal
 | 
			
		||||
                            {
 | 
			
		||||
                                Expression read2ExpAssign = null; //加速缓存
 | 
			
		||||
                                if (field.FieldType.IsArray) read2ExpAssign = Expression.New(RowInfo.Constructor,
 | 
			
		||||
                                    GetDataReaderValueBlockExpression(field.FieldType, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                                    //Expression.Call(MethodGetDataReaderValue, new Expression[] { Expression.Constant(field.FieldType), Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                                    GetDataReaderValueBlockExpression(field.FieldType, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })),
 | 
			
		||||
                                    //Expression.Call(MethodGetDataReaderValue, new Expression[] { Expression.Constant(field.FieldType), Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp }) }),
 | 
			
		||||
                                    Expression.Add(dataIndexExp, Expression.Constant(1))
 | 
			
		||||
                                );
 | 
			
		||||
                                else
 | 
			
		||||
@@ -1294,8 +1299,8 @@ namespace FreeSql.Internal
 | 
			
		||||
                                    if (fieldtypeGeneric.IsNullableType()) fieldtypeGeneric = fieldtypeGeneric.GetGenericArguments().First();
 | 
			
		||||
                                    if (fieldtypeGeneric.IsEnum ||
 | 
			
		||||
                                        dicExecuteArrayRowReadClassOrTuple.ContainsKey(fieldtypeGeneric)) read2ExpAssign = Expression.New(RowInfo.Constructor,
 | 
			
		||||
                                            GetDataReaderValueBlockExpression(field.FieldType, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { Expression.Constant(field.FieldType), Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                                            GetDataReaderValueBlockExpression(field.FieldType, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })),
 | 
			
		||||
                                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { Expression.Constant(field.FieldType), Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp }) }),
 | 
			
		||||
                                            Expression.Add(dataIndexExp, Expression.Constant(1))
 | 
			
		||||
                                    );
 | 
			
		||||
                                    else
 | 
			
		||||
@@ -1336,8 +1341,8 @@ namespace FreeSql.Internal
 | 
			
		||||
                                Expression.IfThen(
 | 
			
		||||
                                    Expression.LessThan(dataIndexExp, rowLenExp),
 | 
			
		||||
                                        Expression.Return(returnTarget, Expression.New(RowInfo.Constructor,
 | 
			
		||||
                                            GetDataReaderValueBlockExpression(type, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)),
 | 
			
		||||
                                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { typeExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp) }),
 | 
			
		||||
                                            GetDataReaderValueBlockExpression(type, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })),
 | 
			
		||||
                                            //Expression.Call(MethodGetDataReaderValue, new Expression[] { typeExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp }) }),
 | 
			
		||||
                                            Expression.Add(dataIndexExp, Expression.Constant(1))))
 | 
			
		||||
                                ),
 | 
			
		||||
                                Expression.Label(returnTarget, Expression.Default(typeof(RowInfo)))
 | 
			
		||||
@@ -1391,7 +1396,7 @@ namespace FreeSql.Internal
 | 
			
		||||
                            var readType = typetb.ColumnsByCs.TryGetValue(ctorParm.Name, out var trycol) ? trycol.Attribute.MapType : ctorParm.ParameterType;
 | 
			
		||||
 | 
			
		||||
                            var ispkExp = new List<Expression>();
 | 
			
		||||
                            Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp));
 | 
			
		||||
                            Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp }));
 | 
			
		||||
                            Expression readExpAssign = null; //加速缓存
 | 
			
		||||
                            if (readType.IsArray) readExpAssign = Expression.New(RowInfo.Constructor,
 | 
			
		||||
                                GetDataReaderValueBlockExpression(readType, readpkvalExp),
 | 
			
		||||
@@ -1407,7 +1412,7 @@ namespace FreeSql.Internal
 | 
			
		||||
                                {
 | 
			
		||||
 | 
			
		||||
                                    //判断主键为空,则整个对象不读取
 | 
			
		||||
                                    //blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)));
 | 
			
		||||
                                    //blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })));
 | 
			
		||||
                                    if (trycol?.Attribute.IsPrimary == true)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        ispkExp.Add(
 | 
			
		||||
@@ -1498,7 +1503,7 @@ namespace FreeSql.Internal
 | 
			
		||||
 | 
			
		||||
                            var ispkExp = new List<Expression>();
 | 
			
		||||
                            var propGetSetMethod = prop.GetSetMethod(true);
 | 
			
		||||
                            Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, tryidxExp));
 | 
			
		||||
                            Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, tryidxExp }));
 | 
			
		||||
                            Expression readExpAssign = null; //加速缓存
 | 
			
		||||
                            if (readType.IsArray) readExpAssign = Expression.New(RowInfo.Constructor,
 | 
			
		||||
                                GetDataReaderValueBlockExpression(readType, readpkvalExp),
 | 
			
		||||
@@ -1514,7 +1519,7 @@ namespace FreeSql.Internal
 | 
			
		||||
                                {
 | 
			
		||||
 | 
			
		||||
                                    //判断主键为空,则整个对象不读取
 | 
			
		||||
                                    //blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)));
 | 
			
		||||
                                    //blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(MethodDataReaderGetValue, new Expression[] { commonUtilExp, rowExp, dataIndexExp })));
 | 
			
		||||
                                    if (flagStr.StartsWith("adoQuery") == false && //Ado.Query 的时候不作此判断
 | 
			
		||||
                                        trycol?.Attribute.IsPrimary == true) //若主键值为 null,则整行读取出来的对象为 null
 | 
			
		||||
                                    {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user