static void Method_DbFunctions_DiffMicroseconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_DbFunctions_DiffMicroseconds);

            throw UtilExceptions.NotSupportedMethod(exp.Method);
        }
        static void Method_DbFunctions_DiffYears(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_DbFunctions_DiffYears);

            Append_DiffYears(generator, exp.Arguments[0], exp.Arguments[1]);
        }
        static void Method_DbFunctions_DiffSeconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_DbFunctions_DiffSeconds);

            Append_DateDiff(generator, exp.Arguments[0], exp.Arguments[1], 24 * 60 * 60);
        }
        static void Method_DateTime_AddSeconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethodDeclaringType(exp, UtilConstants.TypeOfDateTime);

            DbFunction_DATEADD(generator, "seconds", exp);
        }
        static void Method_Guid_NewGuid(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_Guid_NewGuid);

            throw UtilExceptions.NotSupportedMethod(exp.Method);
        }
Exemple #6
0
 static void Method_Min(DbMethodCallExpression exp, SqlGenerator generator)
 {
     EnsureMethodDeclaringType(exp, typeof(AggregateFunctions), UtilConstants.TypeOfSql);
     Aggregate_Min(generator, exp.Arguments.First(), exp.Method.ReturnType);
 }
 static void Method_Average(DbMethodCallExpression exp, SqlGenerator generator)
 {
     EnsureMethodDeclaringType(exp, typeof(AggregateFunctions));
     Aggregate_Average(generator, exp.Arguments.First(), exp.Method.ReturnType);
 }
Exemple #8
0
 static void Aggregate_Average(SqlGenerator generator, DbExpression exp, Type retType)
 {
     AppendAggregateFunction(generator, exp, retType, "AVG", true);
 }
        static void StringConcat(DbBinaryExpression exp, SqlGenerator generator)
        {
            List <DbExpression> operands = new List <DbExpression>();

            operands.Add(exp.Right);

            DbExpression    left = exp.Left;
            DbAddExpression e    = null;

            while ((e = (left as DbAddExpression)) != null && (e.Method == UtilConstants.MethodInfo_String_Concat_String_String || e.Method == UtilConstants.MethodInfo_String_Concat_Object_Object))
            {
                operands.Add(e.Right);
                left = e.Left;
            }

            operands.Add(left);

            DbExpression        whenExp     = null;
            List <DbExpression> operandExps = new List <DbExpression>(operands.Count);

            for (int i = operands.Count - 1; i >= 0; i--)
            {
                DbExpression operand = operands[i];
                DbExpression opBody  = operand;
                if (opBody.Type != UtilConstants.TypeOfString)
                {
                    // 需要 cast type
                    opBody = DbExpression.Convert(opBody, UtilConstants.TypeOfString);
                }

                DbExpression equalNullExp = DbExpression.Equal(opBody, UtilConstants.DbConstant_Null_String);

                if (whenExp == null)
                {
                    whenExp = equalNullExp;
                }
                else
                {
                    whenExp = DbExpression.And(whenExp, equalNullExp);
                }

                operandExps.Add(opBody);
            }

            generator._sqlBuilder.Append("CASE", " WHEN ");
            whenExp.Accept(generator);
            generator._sqlBuilder.Append(" THEN ");
            DbConstantExpression.Null.Accept(generator);
            generator._sqlBuilder.Append(" ELSE ");

            generator._sqlBuilder.Append("(");

            for (int i = 0; i < operandExps.Count; i++)
            {
                if (i > 0)
                {
                    generator._sqlBuilder.Append(" || ");
                }

                generator._sqlBuilder.Append("IFNULL(");
                operandExps[i].Accept(generator);
                generator._sqlBuilder.Append(",");
                DbConstantExpression.StringEmpty.Accept(generator);
                generator._sqlBuilder.Append(")");
            }

            generator._sqlBuilder.Append(")");

            generator._sqlBuilder.Append(" END");
        }
Exemple #10
0
 static void Aggregate_LongCount(SqlGenerator generator)
 {
     generator._sqlBuilder.Append("COUNT(1)");
 }
Exemple #11
0
 static void Aggregate_Min(SqlGenerator generator, DbExpression exp, Type retType)
 {
     AppendAggregateFunction(generator, exp, retType, "MIN", false);
 }
Exemple #12
0
        static void Method_Contains(DbMethodCallExpression exp, SqlGenerator generator)
        {
            MethodInfo method = exp.Method;

            if (method.DeclaringType == UtilConstants.TypeOfString)
            {
                Method_String_Contains(exp, generator);
                return;
            }

            List <DbExpression> exps    = new List <DbExpression>();
            IEnumerable         values  = null;
            DbExpression        operand = null;

            Type declaringType = method.DeclaringType;

            if (typeof(IList).IsAssignableFrom(declaringType) || (declaringType.IsGenericType && typeof(ICollection <>).MakeGenericType(declaringType.GetGenericArguments()).IsAssignableFrom(declaringType)))
            {
                if (exp.Object.NodeType == DbExpressionType.SqlQuery)
                {
                    /* where Id in(select id from T) */

                    operand = exp.Arguments[0];
                    In(generator, (DbSqlQueryExpression)exp.Object, operand);
                    return;
                }

                DbMemberExpression memberExp = exp.Object as DbMemberExpression;

                if (memberExp == null || !memberExp.IsEvaluable())
                {
                    throw new NotSupportedException(exp.ToString());
                }

                values  = DbExpressionExtension.Evaluate(memberExp) as IEnumerable; //Enumerable
                operand = exp.Arguments[0];
                goto constructInState;
            }
            if (method.IsStatic && declaringType == typeof(Enumerable) && exp.Arguments.Count == 2)
            {
                DbExpression arg0 = exp.Arguments[0];
                if (arg0.NodeType == DbExpressionType.SqlQuery)
                {
                    /* where Id in(select id from T) */

                    operand = exp.Arguments[1];
                    In(generator, (DbSqlQueryExpression)arg0, operand);
                    return;
                }

                DbMemberExpression memberExp = arg0 as DbMemberExpression;

                if (memberExp == null || !memberExp.IsEvaluable())
                {
                    throw new NotSupportedException(exp.ToString());
                }

                values  = DbExpressionExtension.Evaluate(memberExp) as IEnumerable;
                operand = exp.Arguments[1];
                goto constructInState;
            }

            throw UtilExceptions.NotSupportedMethod(exp.Method);

constructInState:
            foreach (object value in values)
            {
                if (value == null)
                {
                    exps.Add(DbExpression.Constant(null, operand.Type));
                }
                else
                {
                    Type valueType = value.GetType();
                    if (valueType.IsEnum)
                    {
                        valueType = Enum.GetUnderlyingType(valueType);
                    }

                    if (Utils.IsToStringableNumericType(valueType))
                    {
                        exps.Add(DbExpression.Constant(value));
                    }
                    else
                    {
                        exps.Add(DbExpression.Parameter(value));
                    }
                }
            }
            In(generator, exps, operand);
        }
Exemple #13
0
        static void Method_DiffMicroseconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethodDeclaringType(exp, typeof(DbFunctions), UtilConstants.TypeOfSql);

            throw UtilExceptions.NotSupportedMethod(exp.Method);
        }
Exemple #14
0
        static void Method_DiffSeconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethodDeclaringType(exp, typeof(DbFunctions), UtilConstants.TypeOfSql);

            Append_DateDiff(generator, exp.Arguments[0], exp.Arguments[1], 24 * 60 * 60);
        }
Exemple #15
0
 static void Aggregate_LongCount(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_LongCount(generator);
 }
 static void Method_LongCount(DbMethodCallExpression exp, SqlGenerator generator)
 {
     EnsureMethodDeclaringType(exp, typeof(AggregateFunctions));
     Aggregate_LongCount(generator);
 }
Exemple #17
0
 static void Aggregate_Average(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_Average(generator, exp.Arguments.First(), exp.Method.ReturnType);
 }
Exemple #18
0
 static void Method_Count(DbMethodCallExpression exp, SqlGenerator generator)
 {
     EnsureMethodDeclaringType(exp, typeof(AggregateFunctions), UtilConstants.TypeOfSql);
     Aggregate_Count(generator);
 }