public override string ToDate(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" DATETIME({0})", parameter.MemberName));
        }
Exemplo n.º 2
0
        protected void Where(ExpressionParameter parameter, bool?isLeft, string name, IEnumerable <Expression> args, MethodCallExpressionModel model, List <MethodCallExpressionArgs> appendArgs = null)
        {
            foreach (var item in args)
            {
                var expItem = item;
                if (item is UnaryExpression)
                {
                    expItem = (item as UnaryExpression).Operand;
                }
                AppendItem(parameter, name, args, model, expItem);
            }
            if (appendArgs != null)
            {
                model.Args.AddRange(appendArgs);
            }
            var methodValue = GetMethodValue(name, model);

            if (parameter.BaseExpression is BinaryExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType && name == "HasValue" && !(parameter.OppsiteExpression is BinaryExpression) && !(parameter.OppsiteExpression is MethodCallExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType))
            {
                methodValue = packIfElse(methodValue);
            }
            if (parameter.OppsiteExpression != null && name == "IsNullOrEmpty" && parameter.OppsiteExpression.Type == UtilConstants.BoolType && parameter.OppsiteExpression is ConstantExpression)
            {
                methodValue = packIfElse(methodValue);
            }
            var isRoot = contextIndex == 2;

            if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("ToBool", "ToBoolean")))
            {
                methodValue = methodValue + "=1 ";
                ;
            }
            if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is ConditionalExpression) && ((parameter.CurrentExpression as ConditionalExpression).Type == UtilConstants.BoolType))
            {
                methodValue = methodValue + "=1 ";
            }
            if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("IIF")) && (parameter.CurrentExpression as MethodCallExpression).Method.ReturnType == UtilConstants.BoolType)
            {
                methodValue = methodValue + "=1 ";
            }
            if (parameter.BaseExpression != null && ExpressionTool.IsLogicOperator(parameter.BaseExpression) && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is ConditionalExpression) && ((parameter.CurrentExpression as ConditionalExpression).Type == UtilConstants.BoolType))
            {
                methodValue = methodValue + "=1 ";
            }
            if (parameter.BaseExpression != null && ExpressionTool.IsLogicOperator(parameter.BaseExpression) && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("IIF")) && (parameter.CurrentExpression as MethodCallExpression).Method.ReturnType == UtilConstants.BoolType)
            {
                methodValue = methodValue + "=1 ";
            }
            if (parameter.BaseExpression != null && ExpressionTool.IsLogicOperator(parameter.BaseExpression) && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("ToBool", "ToBoolean")))
            {
                methodValue = methodValue + "=1 ";
            }
            base.AppendValue(parameter, isLeft, methodValue);
        }
Exemplo n.º 3
0
 private void AppendModelByIIFBinary(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
 {
     Check.Exception(true, "The SqlFunc.IIF(arg1,arg2,arg3) , {0} argument  do not support ", item.ToString());
 }
Exemplo n.º 4
0
        public override string ToInt64(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS Number)", parameter.MemberName));
        }
Exemplo n.º 5
0
 protected void Field(ExpressionParameter parameter, bool?isLeft, string name, IEnumerable <Expression> args, MethodCallExpressionModel model, List <MethodCallExpressionArgs> appendArgs = null)
 {
     if (this.Context.ResolveType == ResolveExpressType.FieldSingle)
     {
         this.Context.ResolveType = ResolveExpressType.WhereSingle;
     }
     else
     {
         this.Context.ResolveType = ResolveExpressType.WhereMultiple;
     }
     Where(parameter, isLeft, name, args, model);
 }
Exemplo n.º 6
0
        public override string ToDate(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" to_date({0},'yyyy-mm-dd hh24:mi:ss')", parameter.MemberName));
        }
Exemplo n.º 7
0
        public override string Length(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" LENGTH({0}) ", parameter.MemberName));
        }
Exemplo n.º 8
0
        public virtual string ToInt64(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS BIGINT)", parameter.MemberName));
        }
Exemplo n.º 9
0
        public virtual string ToString(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS NVARCHAR(MAX))", parameter.MemberName));
        }
Exemplo n.º 10
0
        private object GetMethodValue(string name, MethodCallExpressionModel model)
        {
            if (IsExtMethod(name))
            {
                model.Expression     = this.Expression;
                model.BaseExpression = this.BaseParameter.CurrentExpression;
                DbType type = DbType.SqlServer;
                if (this.Context is SqlServerExpressionContext)
                {
                    type = DbType.SqlServer;
                }
                else if (this.Context is MySqlExpressionContext)
                {
                    type = DbType.MySql;
                }
                else if (this.Context is SqliteExpressionContext)
                {
                    type = DbType.Sqlite;
                }
                else if (this.Context is OracleExpressionContext)
                {
                    type = DbType.Oracle;
                }
                return(this.Context.SqlFuncServices.First(it => it.UniqueMethodName == name).MethodValue(model, type, this.Context));
            }
            else
            {
                if (name == "Parse" && TempParseType.IsIn(UtilConstants.GuidType) && model.Args != null && model.Args.Count() > 1)
                {
                    name = "Equals";
                }
                else if (name == "Parse")
                {
                    name = "To" + TempParseType.Name;
                }
                switch (name)
                {
                case "IIF":
                    return(this.Context.DbMehtods.IIF(model));

                case "HasNumber":
                    return(this.Context.DbMehtods.HasNumber(model));

                case "HasValue":
                    return(this.Context.DbMehtods.HasValue(model));

                case "IsNullOrEmpty":
                    return(this.Context.DbMehtods.IsNullOrEmpty(model));

                case "ToLower":
                    return(this.Context.DbMehtods.ToLower(model));

                case "ToUpper":
                    return(this.Context.DbMehtods.ToUpper(model));

                case "Trim":
                    return(this.Context.DbMehtods.Trim(model));

                case "Contains":
                    return(this.Context.DbMehtods.Contains(model));

                case "ContainsArray":
                    if (model.Args[0].MemberValue == null)
                    {
                        var first = this.Context.Parameters.FirstOrDefault(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                        if (first.HasValue())
                        {
                            model.Args[0].MemberValue = first.Value;
                        }
                    }
                    var caResult = this.Context.DbMehtods.ContainsArray(model);
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                    return(caResult);

                case "ContainsArrayUseSqlParameters":
                    if (model.Args[0].MemberValue == null)
                    {
                        var first = this.Context.Parameters.FirstOrDefault(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                        if (first.HasValue())
                        {
                            model.Args[0].MemberValue = first.Value;
                        }
                    }
                    model.Data = this.Context.SqlParameterKeyWord + "INP_" + this.Context.ParameterIndex;
                    this.Context.ParameterIndex++;
                    if (model.Args[0].MemberValue.HasValue())
                    {
                        var inValueIEnumerable = (IEnumerable)model.Args[0].MemberValue;
                        int i = 0;
                        foreach (var item in inValueIEnumerable)
                        {
                            this.Context.Parameters.Add(new SugarParameter(model.Data + "_" + i, item));
                            i++;
                        }
                    }
                    var caResult2 = this.Context.DbMehtods.ContainsArrayUseSqlParameters(model);
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                    return(caResult2);

                case "Equals":
                    return(this.Context.DbMehtods.Equals(model));

                case "EqualsNull":
                    return(this.Context.DbMehtods.EqualsNull(model));

                case "DateIsSame":
                    if (model.Args.Count == 2)
                    {
                        return(this.Context.DbMehtods.DateIsSameDay(model));
                    }
                    else
                    {
                        var dsResult = this.Context.DbMehtods.DateIsSameByType(model);
                        this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[2].MemberName.ObjToString());
                        return(dsResult);
                    }

                case "DateAdd":
                    if (model.Args.Count == 2)
                    {
                        return(this.Context.DbMehtods.DateAddDay(model));
                    }
                    else
                    {
                        var daResult = this.Context.DbMehtods.DateAddByType(model);
                        this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[2].MemberName.ObjToString());
                        return(daResult);
                    }

                case "DateValue":
                    var dvResult = this.Context.DbMehtods.DateValue(model);
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
                    return(dvResult);

                case "Between":
                    return(this.Context.DbMehtods.Between(model));

                case "StartsWith":
                    return(this.Context.DbMehtods.StartsWith(model));

                case "EndsWith":
                    return(this.Context.DbMehtods.EndsWith(model));

                case "ToInt32":
                    return(this.Context.DbMehtods.ToInt32(model));

                case "ToInt64":
                    return(this.Context.DbMehtods.ToInt64(model));

                case "ToDate":
                    return(this.Context.DbMehtods.ToDate(model));

                case "ToDateTime":
                    return(this.Context.DbMehtods.ToDate(model));

                case "ToTime":
                    return(this.Context.DbMehtods.ToTime(model));

                case "ToString":
                    if (model.Args.Count > 1 && model.Args.Last().MemberValue.ObjToString().IsContainsIn("-", "/", ":", "yy", "ms", "hh"))
                    {
                        return(GeDateFormat(model.Args.Last().MemberValue.ObjToString(), model.Args.First().MemberName.ObjToString()));
                    }
                    Check.Exception(model.Args.Count > 1, "ToString (Format) is not supported, Use ToString().If time formatting can be used it.Date.Year+\"-\"+it.Data.Month+\"-\"+it.Date.Day ");
                    return(this.Context.DbMehtods.ToString(model));

                case "ToVarchar":
                    return(this.Context.DbMehtods.ToVarchar(model));

                case "ToDecimal":
                    return(this.Context.DbMehtods.ToDecimal(model));

                case "ToGuid":
                    return(this.Context.DbMehtods.ToGuid(model));

                case "ToDouble":
                    return(this.Context.DbMehtods.ToDouble(model));

                case "ToBool":
                    return(this.Context.DbMehtods.ToBool(model));

                case "ToBoolean":
                    return(this.Context.DbMehtods.ToBool(model));

                case "Substring":
                    return(this.Context.DbMehtods.Substring(model));

                case "Replace":
                    return(this.Context.DbMehtods.Replace(model));

                case "Length":
                    return(this.Context.DbMehtods.Length(model));

                case "AggregateSum":
                    return(this.Context.DbMehtods.AggregateSum(model));

                case "AggregateAvg":
                    return(this.Context.DbMehtods.AggregateAvg(model));

                case "AggregateMin":
                    return(this.Context.DbMehtods.AggregateMin(model));

                case "AggregateMax":
                    return(this.Context.DbMehtods.AggregateMax(model));

                case "AggregateCount":
                    return(this.Context.DbMehtods.AggregateCount(model));

                case "AggregateDistinctCount":
                    return(this.Context.DbMehtods.AggregateDistinctCount(model));

                case "MappingColumn":
                    var mappingColumnResult = this.Context.DbMehtods.MappingColumn(model);
                    var isValid             = model.Args[0].IsMember && model.Args[1].IsMember == false;
                    Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
                    return(mappingColumnResult);

                case "IsNull":
                    return(this.Context.DbMehtods.IsNull(model));

                case "MergeString":
                    return(this.Context.DbMehtods.MergeString(model.Args.Select(it => it.MemberName.ObjToString()).ToArray()));

                case "GetSelfAndAutoFill":
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                    return(this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle));

                case "GetDate":
                    return(this.Context.DbMehtods.GetDate());

                case "GetRandom":
                    return(this.Context.DbMehtods.GetRandom());

                case "CharIndex":
                    return(this.Context.DbMehtods.CharIndex(model));

                default:
                    break;
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        public string GeDateFormat(string formatString, string value)
        {
            var parameter = new MethodCallExpressionArgs()
            {
                IsMember = true, MemberValue = DateType.Year
            };
            var parameter2 = new MethodCallExpressionArgs()
            {
                IsMember = true, MemberName = value
            };
            var parameters = new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
                {
                    parameter2, parameter
                }
            };
            var begin = @"^";
            var end   = @"$";

            formatString = formatString.Replace("yyyy", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("yy", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Month;
            formatString = formatString.Replace("MM", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("M", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Day;
            formatString = formatString.Replace("dd", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("d", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Hour;
            formatString = Regex.Replace(formatString, "hh", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end, RegexOptions.IgnoreCase);
            formatString = Regex.Replace(formatString, "h", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end, RegexOptions.IgnoreCase);

            parameters.Args.Last().MemberValue = DateType.Minute;
            formatString = formatString.Replace("mm", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("m", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Second;
            formatString = formatString.Replace("ss", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            formatString = formatString.Replace("s", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);

            parameters.Args.Last().MemberValue = DateType.Millisecond;
            formatString = formatString.Replace("ms", begin + UtilMethods.ConvertStringToNumbers(this.GetMethodValue("DateValue", parameters).ObjToString()) + end);
            var items = Regex.Matches(formatString, @"\^\d+\$").Cast <Match>().ToList();

            foreach (var item in items)
            {
                formatString = formatString.Replace(item.Value, "$@" + UtilMethods.ConvertNumbersToString(item.Value.TrimStart('^').TrimEnd('$')) + "$");
            }
            var strings             = formatString.TrimStart('$').TrimEnd('$').Split('$');
            var joinStringParameter = new MethodCallExpressionModel()
            {
                Args = new List <MethodCallExpressionArgs>()
            };

            foreach (var r in strings)
            {
                if (r.Substring(0, 1) == "@")
                {
                    joinStringParameter.Args.Add(new MethodCallExpressionArgs()
                    {
                        MemberName = r.TrimStart('@')
                    });
                }
                else
                {
                    var name = base.AppendParameter(r);
                    joinStringParameter.Args.Add(new MethodCallExpressionArgs()
                    {
                        MemberName = name
                    });
                }
            }
            return(this.GetMethodValue("MergeString", joinStringParameter).ObjToString());
        }
Exemplo n.º 12
0
        public override string HasValue(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format("( {0} IS NOT NULL )", parameter.MemberName));
        }
 public override string CharIndex(MethodCallExpressionModel model)
 {
     throw new NotSupportedException("Slqite Not Supported CharIndex");
 }
        public override string ToDateShort(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" strftime('%Y-%m-%d', {0})", parameter.MemberName));
        }
Exemplo n.º 15
0
        public override string ToDecimal(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS DECIMAL(18,4))", parameter.MemberName));
        }
Exemplo n.º 16
0
        public virtual string IsNullOrEmpty(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format("( {0}='' OR {0} IS NULL )", parameter.MemberName));
        }
Exemplo n.º 17
0
        public override string ToString(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS VARCHAR2(4000))", parameter.MemberName));
        }
Exemplo n.º 18
0
        public virtual string ToGuid(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS UNIQUEIDENTIFIER)", parameter.MemberName));
        }
Exemplo n.º 19
0
 public override string DateIsSameByType(MethodCallExpressionModel model)
 {
     throw new NotSupportedException("Oracle NotSupportedException DateIsSameDay");
 }
Exemplo n.º 20
0
        public virtual string ToDate(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS DATETIME)", parameter.MemberName));
        }
Exemplo n.º 21
0
 public override string CharIndex(MethodCallExpressionModel model)
 {
     return(string.Format("instr ({0},{1},1,1) ", model.Args[0].MemberName, model.Args[1].MemberName));
 }
Exemplo n.º 22
0
        public virtual string ToDecimal(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" CAST({0} AS MONEY)", parameter.MemberName));
        }
Exemplo n.º 23
0
        public override string ToTime(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" to_timestamp({0},'0000-01-01 hh24:mi:ss') ", parameter.MemberName));
        }
Exemplo n.º 24
0
        public virtual string AggregateCount(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format("COUNT({0})", parameter.MemberName));
        }
Exemplo n.º 25
0
 protected void Select(ExpressionParameter parameter, bool?isLeft, string name, IEnumerable <Expression> args, MethodCallExpressionModel model, List <MethodCallExpressionArgs> appendArgs = null)
 {
     if (name == "GetSelfAndAutoFill")
     {
         var memberValue = (args.First() as MemberExpression).Expression.ToString();
         model.Args.Add(new MethodCallExpressionArgs()
         {
             MemberValue = memberValue, IsMember = true, MemberName = memberValue
         });
     }
     else
     {
         foreach (var item in args)
         {
             AppendItem(parameter, name, args, model, item);
         }
         if (appendArgs != null)
         {
             model.Args.AddRange(appendArgs);
         }
     }
     if (parameter.BaseParameter.BaseParameter.BaseParameter == null)
     {
         this.Context.Result.Append(GetMethodValue(name, model));
     }
     else
     {
         parameter.BaseParameter.CommonTempData = GetMethodValue(name, model);
     }
 }
Exemplo n.º 26
0
        public virtual string HasNumber(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format("( {0}>0 AND {0} IS NOT NULL )", parameter.MemberName));
        }
Exemplo n.º 27
0
        private void AppendItem(ExpressionParameter parameter, string name, IEnumerable <Expression> args, MethodCallExpressionModel model, Expression item)
        {
            if (ExpressionTool.IsUnConvertExpress(item))
            {
                item = (item as UnaryExpression).Operand;
            }
            var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
            var isConst            = item is ConstantExpression;
            var isIIF           = name == "IIF";
            var isIFFBoolMember = isIIF && (item is MemberExpression) && (item as MemberExpression).Type == UtilConstants.BoolType;
            var isIFFUnary      = isIIF && (item is UnaryExpression) && (item as UnaryExpression).Operand.Type == UtilConstants.BoolType;
            var isIFFBoolBinary = isIIF && (item is BinaryExpression) && (item as BinaryExpression).Type == UtilConstants.BoolType;
            var isIFFBoolMethod = isIIF && (item is MethodCallExpression) && (item as MethodCallExpression).Type == UtilConstants.BoolType;
            var isFirst         = item == args.First();

            if (isFirst && isIIF && isConst)
            {
                var value = (item as ConstantExpression).Value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False();
                var methodCallExpressionArgs = new MethodCallExpressionArgs()
                {
                    IsMember    = true,
                    MemberName  = value,
                    MemberValue = value
                };
                model.Args.Add(methodCallExpressionArgs);
            }
            else if (isIFFUnary && !isFirst)
            {
                AppendModelByIIFMember(parameter, model, (item as UnaryExpression).Operand);
            }
            else if (isIFFBoolMember && !isFirst)
            {
                AppendModelByIIFMember(parameter, model, item);
            }
            else if (isIFFBoolBinary && !isFirst)
            {
                AppendModelByIIFBinary(parameter, model, item);
            }
            else if (isIFFBoolMethod && !isFirst)
            {
                AppendModelByIIFMethod(parameter, model, item);
            }
            else if (isBinaryExpression)
            {
                model.Args.Add(GetMethodCallArgs(parameter, item));
            }
            else
            {
                AppendModel(parameter, model, item);
            }
        }
Exemplo n.º 28
0
        public virtual string Trim(MethodCallExpressionModel model)
        {
            var parameter = model.Args[0];

            return(string.Format(" (rtrim(ltrim({0}))) ", parameter.MemberName));
        }
Exemplo n.º 29
0
        private void AppendModel(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
        {
            parameter.CommonTempData = CommonTempDataType.Result;
            base.Expression          = item;
            if (item.Type == UtilConstants.DateType && parameter.CommonTempData.ObjToString() == CommonTempDataType.Result.ToString() && item.ToString() == "DateTime.Now.Date")
            {
                parameter.CommonTempData = DateTime.Now.Date;
            }
            else if (IsDateDate(item))
            {
                parameter.CommonTempData = GetNewExpressionValue(item);
            }
            else if (IsDateValue(item))
            {
                parameter.CommonTempData = GetNewExpressionValue(item);
            }
            else if (model.Name == "ToString" && item is ConstantExpression && (item as ConstantExpression).Type.IsEnum())
            {
                parameter.CommonTempData = item.ToString();
            }
            else
            {
                base.Start();
            }
            var methodCallExpressionArgs = new MethodCallExpressionArgs()
            {
                IsMember   = parameter.ChildExpression is MemberExpression && !ExpressionTool.IsConstExpression(parameter.ChildExpression as MemberExpression),
                MemberName = parameter.CommonTempData
            };

            if (methodCallExpressionArgs.IsMember && parameter.ChildExpression != null && parameter.ChildExpression.ToString() == "DateTime.Now")
            {
                methodCallExpressionArgs.IsMember = false;
            }
            var value = methodCallExpressionArgs.MemberName;

            if (methodCallExpressionArgs.IsMember)
            {
                var childExpression = parameter.ChildExpression as MemberExpression;
                if (childExpression.Expression != null && childExpression.Expression is ConstantExpression)
                {
                    methodCallExpressionArgs.IsMember = false;
                }
            }
            if (IsDateDate(item) || IsDateValue(item))
            {
                methodCallExpressionArgs.IsMember = true;
            }
            if (methodCallExpressionArgs.IsMember == false && (item is MethodCallExpression && item.ToString() == "GetDate()") || (item is UnaryExpression && ((UnaryExpression)item).Operand.ToString() == "GetDate()"))
            {
                var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
                this.Context.ParameterIndex++;
                methodCallExpressionArgs.MemberName  = value;
                methodCallExpressionArgs.MemberValue = null;
            }
            else if (methodCallExpressionArgs.IsMember == false)
            {
                var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.MethodConst + this.Context.ParameterIndex;
                this.Context.ParameterIndex++;
                methodCallExpressionArgs.MemberName  = parameterName;
                methodCallExpressionArgs.MemberValue = value;
                this.Context.Parameters.Add(new SugarParameter(parameterName, value));
            }
            model.Args.Add(methodCallExpressionArgs);
            parameter.ChildExpression = null;
        }
        private object GetMdthodValue(string name, MethodCallExpressionModel model)
        {
            if (IsExtMethod(name))
            {
                DbType type = DbType.SqlServer;
                if (this.Context is SqlServerExpressionContext)
                {
                    type = DbType.SqlServer;
                }
                else if (this.Context is MySqlExpressionContext)
                {
                    type = DbType.MySql;
                }
                else if (this.Context is SqliteExpressionContext)
                {
                    type = DbType.Sqlite;
                }
                else if (this.Context is OracleExpressionContext)
                {
                    type = DbType.Oracle;
                }
                return(this.Context.SqlFuncServices.First(it => it.UniqueMethodName == name).MethodValue(model, type, this.Context));
            }
            else
            {
                switch (name)
                {
                case "IIF":
                    return(this.Context.DbMehtods.IIF(model));

                case "HasNumber":
                    return(this.Context.DbMehtods.HasNumber(model));

                case "HasValue":
                    return(this.Context.DbMehtods.HasValue(model));

                case "IsNullOrEmpty":
                    return(this.Context.DbMehtods.IsNullOrEmpty(model));

                case "ToLower":
                    return(this.Context.DbMehtods.ToLower(model));

                case "ToUpper":
                    return(this.Context.DbMehtods.ToUpper(model));

                case "Trim":
                    return(this.Context.DbMehtods.Trim(model));

                case "Contains":
                    return(this.Context.DbMehtods.Contains(model));

                case "ContainsArray":
                    var caResult = this.Context.DbMehtods.ContainsArray(model);
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                    return(caResult);

                case "Equals":
                    return(this.Context.DbMehtods.Equals(model));

                case "DateIsSame":
                    if (model.Args.Count == 2)
                    {
                        return(this.Context.DbMehtods.DateIsSameDay(model));
                    }
                    else
                    {
                        var dsResult = this.Context.DbMehtods.DateIsSameByType(model);
                        this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[2].MemberName.ObjToString());
                        return(dsResult);
                    }

                case "DateAdd":
                    if (model.Args.Count == 2)
                    {
                        return(this.Context.DbMehtods.DateAddDay(model));
                    }
                    else
                    {
                        var daResult = this.Context.DbMehtods.DateAddByType(model);
                        this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[2].MemberName.ObjToString());
                        return(daResult);
                    }

                case "DateValue":
                    var dvResult = this.Context.DbMehtods.DateValue(model);
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
                    return(dvResult);

                case "Between":
                    return(this.Context.DbMehtods.Between(model));

                case "StartsWith":
                    return(this.Context.DbMehtods.StartsWith(model));

                case "EndsWith":
                    return(this.Context.DbMehtods.EndsWith(model));

                case "ToInt32":
                    return(this.Context.DbMehtods.ToInt32(model));

                case "ToInt64":
                    return(this.Context.DbMehtods.ToInt64(model));

                case "ToDate":
                    return(this.Context.DbMehtods.ToDate(model));

                case "ToTime":
                    return(this.Context.DbMehtods.ToTime(model));

                case "ToString":
                    Check.Exception(model.Args.Count > 1, "ToString (Format) is not supported, Use ToString().If time formatting can be used it.Date.Year+\"-\"+it.Data.Month+\"-\"+it.Date.Day ");
                    return(this.Context.DbMehtods.ToString(model));

                case "ToDecimal":
                    return(this.Context.DbMehtods.ToDecimal(model));

                case "ToGuid":
                    return(this.Context.DbMehtods.ToGuid(model));

                case "ToDouble":
                    return(this.Context.DbMehtods.ToDouble(model));

                case "ToBool":
                    return(this.Context.DbMehtods.ToBool(model));

                case "Substring":
                    return(this.Context.DbMehtods.Substring(model));

                case "Replace":
                    return(this.Context.DbMehtods.Replace(model));

                case "Length":
                    return(this.Context.DbMehtods.Length(model));

                case "AggregateSum":
                    return(this.Context.DbMehtods.AggregateSum(model));

                case "AggregateAvg":
                    return(this.Context.DbMehtods.AggregateAvg(model));

                case "AggregateMin":
                    return(this.Context.DbMehtods.AggregateMin(model));

                case "AggregateMax":
                    return(this.Context.DbMehtods.AggregateMax(model));

                case "AggregateCount":
                    return(this.Context.DbMehtods.AggregateCount(model));

                case "MappingColumn":
                    var mappingColumnResult = this.Context.DbMehtods.MappingColumn(model);
                    var isValid             = model.Args[0].IsMember && model.Args[1].IsMember == false;
                    Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
                    return(mappingColumnResult);

                case "IsNull":
                    return(this.Context.DbMehtods.IsNull(model));

                case "MergeString":
                    return(this.Context.DbMehtods.MergeString(model.Args.Select(it => it.MemberName.ObjToString()).ToArray()));

                case "GetSelfAndAutoFill":
                    this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
                    return(this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle));

                case "GetDate":
                    return(this.Context.DbMehtods.GetDate());

                default:
                    break;
                }
            }
            return(null);
        }