static void Aggregate_LongCount(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_LongCount(generator);
 }
 static void Aggregate_Average(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_Average(generator, exp.Arguments.First(), exp.Method.ReturnType);
 }
Beispiel #3
0
        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");
        }