Ejemplo n.º 1
0
        private static void TranslateReplace(string methodName, MethodCallExpression expression, QueryPack pack)
        {
            pack.Append("REPLACE(");
            ExpressionTranslator.Translate(expression.Object, pack);

            for (int i = 0, j = 2; i < j; i++)
            {
                pack.Append(", ");
                ExpressionTranslator.Translate(expression.Arguments[i], pack);
            }
            pack.Append(")");
        }
 private static void InnerTranslate(MemberExpression expression, QueryPack pack)
 {
     if (pack.Contains(expression.Expression.Type))
     {
         var table = pack.GetTable(expression.Expression.Type);
         pack.Append($"{table.Alias}.{expression.Member.Name}");
     }
     else
     {
         var name = expression.Member.Name;
         pack.Append($"@{name[0].ToString().ToUpperInvariant()}{name.Substring(1, name.Length - 1)}");
     }
 }
Ejemplo n.º 3
0
        private static void TranslateLikeMethod(string methodName, MethodCallExpression expression, QueryPack pack)
        {
            ExpressionTranslator.Translate(expression.Object, pack);
            pack.Append(" LIKE ");

            if (StringHelper.Compare(methodName, "Contains") || StringHelper.Compare(methodName, "EndsWith"))
            {
                pack.Append("'%'+");
            }

            ExpressionTranslator.Translate(expression.Arguments[0], pack);

            if (StringHelper.Compare(methodName, "Contains") || StringHelper.Compare(methodName, "StartsWith"))
            {
                pack.Append("+'%'");
            }
        }
 private static void InnerTranslate(ConstantExpression expression, QueryPack pack)
 {
     if (expression == null || expression.Value == null)
     {
         pack.Append("NULL");
     }
     else if (expression.Type == typeof(string) || expression.Type == typeof(Guid))
     {
         pack.AppendFormat("N'{0}' ", expression.Value.ToString());
     }
     else if (expression.Type == typeof(bool))
     {
         pack.Append((bool)expression.Value ? "1" : "0");
     }
     else
     {
         pack.AppendFormat("{0} ", expression.Value.ToString());
     }
 }
Ejemplo n.º 5
0
        private void TranslateTop(QuerySegment segment)
        {
            this.pack.State = QueryState.Select;
            this.pack.AppendFormat("SELECT TOP ({0}) ", segment.Count.ToString());

            var table = pack.GetTable(segment.Type);

            if (segment.Expression == null)
            {
                this.pack.AppendFormat("{0}.* ", table.Alias);
            }
            else
            {
                ExpressionTranslator.Translate(segment.Expression.Body, pack);
                pack.Append(string.Join(", ", pack.SelectFields));
                pack.SelectFields.Clear();
            }

            this.pack.AppendFormat(" FROM {0} AS {1}", table.Name, table.Alias);
        }
Ejemplo n.º 6
0
 private static void TranslateToUpper(string methodName, MethodCallExpression expression, QueryPack pack)
 {
     pack.Append("UPPER(");
     ExpressionTranslator.Translate(expression.Object, pack);
     pack.Append(")");
 }
        public static void Translate(ExpressionType nodeType, QueryPack pack, bool isNull)
        {
            switch (nodeType)
            {
            case ExpressionType.And:
            case ExpressionType.AndAlso:
                pack.Append(" AND ");
                break;

            case ExpressionType.Equal:
                pack.Append(isNull ? " IS " : "=");
                break;

            case ExpressionType.GreaterThan:
                pack.Append(">");
                break;

            case ExpressionType.GreaterThanOrEqual:
                pack.Append(">=");
                break;

            case ExpressionType.NotEqual:
                pack.Append(isNull ? " IS NOT " : "!=");
                break;

            case ExpressionType.Or:
            case ExpressionType.OrElse:
                pack.Append(" OR ");
                break;

            case ExpressionType.LessThan:
                pack.Append("<");
                break;

            case ExpressionType.LessThanOrEqual:
                pack.Append("<=");
                break;

            case ExpressionType.Add:
                pack.Append("+");
                break;

            case ExpressionType.Subtract:
                pack.Append("-");
                break;

            case ExpressionType.Multiply:
                pack.Append("*");
                break;

            case ExpressionType.Divide:
                pack.Append("/");
                break;

            case ExpressionType.Modulo:
                pack.Append("%");
                break;

            default:
                throw new NotImplementedException("Unkonw type");
            }
        }