public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     var be = expression as BinaryExpression;
     return be != null
         && (CheckShortCircuitAnd(be, queryBuilder, visitExpression)
             || CheckShortCircuitOr(be, queryBuilder, visitExpression));
 }
Exemple #2
0
 public bool TryMatch(Expression expression, MainQueryParts queryParts, Action<Expression> visitExpression, QueryContext context)
 {
     var sq = expression as SubQueryExpression;
     return sq != null
         && sq.QueryModel.ResultOperators.Count == 1
         && sq.QueryModel.ResultOperators[0] is SumResultOperator
         && CheckShortCircuitSum(sq, queryParts, visitExpression);
 }
 public bool TryMatch(MemberExpression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     MemberCallDelegate mcd;
     if (SupportedMembers.TryGetValue(expression.Member, out mcd))
     {
         mcd(expression, queryBuilder, visitExpression);
         return true;
     }
     return false;
 }
 private static void CurrentDate(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     if (context.CanUseParams)
     {
         queryBuilder.Append("'");
         queryBuilder.Append(context.Time.Value.Today.ToString("yyyy-MM-dd"));
         queryBuilder.Append("'::date");
     }
     else
         queryBuilder.Append("CURRENT_DATE");
 }
 private static void CurrentTimestamp(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     if (context.CanUseParams)
     {
         queryBuilder.Append("'");
         queryBuilder.Append(TimestampConverter.ToDatabase(context.Time.Value.Now));
         queryBuilder.Append("'::timestamptz");
     }
     else
         queryBuilder.Append("CURRENT_TIMESTAMP");
 }
Exemple #6
0
        public SubqueryParts(QueryParts parentQuery, bool canQueryInMemory, Expression selector, QueryContext context)
            : base(parentQuery.Locator,
				context,
				parentQuery.ConverterFactory,
				parentQuery.Simplifications,
				parentQuery.ExpressionMatchers,
				parentQuery.MemberMatchers,
				parentQuery.ProjectionMatchers)
        {
            this.CanQueryInMemory = canQueryInMemory;
            this.ParentQuery = parentQuery;
            this.Selector = selector;
        }
Exemple #7
0
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context, IPostgresConverterFactory converter)
        {
            var mce = expression as MethodCallExpression;
            if (mce == null)
                return false;

            MethodCallDelegate mcd;
            if (SupportedMethods.TryGetValue(mce.Method, out mcd))
            {
                mcd(mce, queryBuilder, visitExpression);
                return true;
            }
            return false;
        }
Exemple #8
0
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
        {
            var mce = expression as MethodCallExpression;
            if (mce == null || !mce.Method.IsGenericMethod)
                return false;

            MethodCallDelegate mcd;
            if (SupportedMethods.TryGetValue(mce.Method.GetGenericMethodDefinition(), out mcd))
            {
                mcd(mce, queryBuilder, visitExpression);
                return true;
            }
            return false;
        }
 public bool TryMatch(MemberExpression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     Dictionary<Type, MemberCallDelegate> dict;
     var member = expression.Member;
     if (member.DeclaringType.IsGenericType && SupportedMembers.TryGetValue(member.Name, out dict))
     {
         MemberCallDelegate mcd;
         if (dict.TryGetValue(member.DeclaringType.GetGenericTypeDefinition(), out mcd))
         {
             mcd(expression, queryBuilder, visitExpression);
             return true;
         }
     }
     return false;
 }
Exemple #10
0
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
        {
            var mce = expression as MethodCallExpression;
            if (mce == null)
                return false;

            MethodCallDelegate mcd;
            var dt = mce.Method.DeclaringType;
            if (dt.IsGenericType && dt.GetGenericTypeDefinition() == typeof(HashSet<>) && SupportedMethods.TryGetValue(mce.Method.Name, out mcd))
            {
                mcd(mce, queryBuilder, visitExpression);
                return true;
            }
            return false;
        }
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
        {
            var mce = expression as MethodCallExpression;
            if (mce == null)
                return false;

            MethodCallDelegate mcd;
            if (SupportedMethods.TryGetValue(mce.Method, out mcd))
            {
                if (mce.Arguments[0] is ConstantExpression == false)
                    return false;
                mcd(mce, queryBuilder, visitExpression);
                return true;
            }
            return false;
        }
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
        {
            var mce = expression as MethodCallExpression;
            if (mce == null || mce.Method.ReturnType != typeof(bool))
                return false;

            queryBuilder.Append(Function).Append('(');
            visitExpression(mce.Arguments[0]);
            foreach (var arg in mce.Arguments.Skip(1))
            {
                queryBuilder.Append(',');
                visitExpression(arg);
            }
            queryBuilder.Append(')');
            return true;
        }
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context, IPostgresConverterFactory converter)
        {
            var be = expression as BinaryExpression;
            if (be == null)
                return false;

            if (expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual)
            {
                var ceZero = be.Right as ConstantExpression ?? be.Left as ConstantExpression;
                var ceMethod = be.Left as MethodCallExpression ?? be.Right as MethodCallExpression;
                if (ceZero == null || ceMethod == null || !ceZero.Value.Equals(0) || !CompareMethods.Contains(ceMethod.Method))
                    return false;

                return CompareString(expression.NodeType == ExpressionType.Equal, ceMethod, queryBuilder, visitExpression);
            }
            return false;
        }
        public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context, IPostgresConverterFactory converter)
        {
            var be = expression as BinaryExpression;
            if (be == null)
                return false;

            if (expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual)
            {
                var nullLeft = IsNullExpression(be.Left);
                var nullRight = IsNullExpression(be.Right);

                if (!nullLeft && nullRight)
                {
                    if (expression.NodeType == ExpressionType.NotEqual)
                        queryBuilder.Append(" (NOT ");
                    visitExpression(be.Left);
                    queryBuilder.Append(" IS NULL ");
                    if (expression.NodeType == ExpressionType.NotEqual)
                        queryBuilder.Append(")");
                    return true;
                }
                else if (nullLeft && !nullRight)
                {
                    if (expression.NodeType == ExpressionType.NotEqual)
                        queryBuilder.Append(" (NOT ");
                    visitExpression(be.Right);
                    queryBuilder.Append(" IS NULL ");
                    if (expression.NodeType == ExpressionType.NotEqual)
                        queryBuilder.Append(")");
                    return true;
                }
                else if (nullLeft && nullRight)
                {
                    if (expression.NodeType == ExpressionType.Equal)
                        queryBuilder.Append(" true ");
                    else
                        queryBuilder.Append(" false ");
                    return true;
                }
            }
            return false;
        }
Exemple #15
0
 private static void GetPrincipal(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     var me = memberCall.Expression as MemberExpression;
     if (me != null && me.NodeType == ExpressionType.MemberAccess)
     {
         var parent = me.Expression as MemberExpression;
         if (parent != null && parent.NodeType == ExpressionType.MemberAccess && parent.Member == CurrentPrincipal)
         {
             if (context.CanUseParams)
             {
                 queryBuilder.Append('\'');
                 queryBuilder.Append(Thread.CurrentPrincipal.Identity.Name.Replace("'", "''"));
                 queryBuilder.Append('\'');
             }
             else queryBuilder.Append("SESSION_USER");
             return;
         }
     }
     throw new NotSupportedException("Invalid member call:" + memberCall);
 }
Exemple #16
0
 public string GetSqlExpression(Expression expression, QueryContext context)
 {
     return(SqlGeneratorExpressionTreeVisitor.GetSqlExpression(expression, this, context));
 }
Exemple #17
0
 private static void GetStringLength(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     queryBuilder.Append("length(");
     visitExpression(memberCall.Expression);
     queryBuilder.Append(")");
 }
 private static void GetTimeSpanTotalHours(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     queryBuilder.Append("extract(day from ");
     visitExpression(memberCall.Expression);
     queryBuilder.AppendFormat(")::int * 24 + extract(hour from ");
     visitExpression(memberCall.Expression);
     queryBuilder.AppendFormat(")");
 }
 private static void GetYear(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     Format(memberCall, queryBuilder, visitExpression, "y");
 }
 private static void GetTimeOfDay(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     visitExpression(memberCall.Expression);
     queryBuilder.AppendFormat("::time");
 }
 private static void GetTimeSpanDays(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     GetTimeSpanTotalDays(memberCall, queryBuilder, visitExpression, context);
     queryBuilder.AppendFormat("::int");
 }
 private static void GetMillisecond(MemberExpression memberCall, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context)
 {
     Format(memberCall, queryBuilder, visitExpression, "ms");
     queryBuilder.Append("%1000");
 }
Exemple #23
0
 public SubqueryParts(QueryParts parentQuery, Expression selector, QueryContext context)
     : this(parentQuery, false, selector, context)
 {
 }
 public static SubqueryParts ParseSubquery(QueryModel queryModel, QueryParts parentQuery, bool canQueryInMemory, QueryContext context)
 {
     var visitor = new SubqueryGeneratorQueryModelVisitor(parentQuery, canQueryInMemory, queryModel.SelectClause.Selector, context);
     visitor.VisitQueryModel(queryModel);
     return visitor.QueryParts;
 }
 private SubqueryGeneratorQueryModelVisitor(QueryParts parentQuery, bool canQueryInMemory, Expression selector, QueryContext context)
 {
     QueryParts = new SubqueryParts(parentQuery, canQueryInMemory, selector, context);
 }
Exemple #26
0
 public bool TryMatch(Expression expression, StringBuilder queryBuilder, Action<Expression> visitExpression, QueryContext context, IPostgresConverterFactory converter)
 {
     var be = expression as BinaryExpression;
     return be != null
         && ArrayIndex(be, queryBuilder, visitExpression);
 }