private object GetScalar(IOqlExpressionVisitor visitor)
 {
     using (IDataSource dataSource = m_data_provider.GetDataSource())
     {
         return(Convert.ChangeType(dataSource.GetScalar(visitor.Query), visitor.Context.CallResult.ResultType));
     }
 }
Beispiel #2
0
 public void FormatNot(IOqlExpressionVisitor visitor, Expression operand)
 {
     visitor.Query.AppendNot();
     visitor.Query.AppendBeginExpression();
     visitor.Visit(operand);
     visitor.Query.AppendEndExpression();
 }
 private int ExecuteCommand(IOqlExpressionVisitor visitor)
 {
     using (IDataSource dataSource = m_data_provider.GetDataSource())
     {
         return(dataSource.ExecuteCommand(visitor.Query));
     }
 }
        public override void FormatMethodCall(IOqlExpressionVisitor visitor, MethodCallExpression methodCall)
        {
            if (methodCall.Method.DeclaringType == typeof(Enumerable))
            {
                visitor.Query.AppendBeginExpression();
                visitor.Visit(methodCall.Arguments[1]);
                visitor.Query.AppendIn();
                visitor.Visit(methodCall.Arguments.First());
                visitor.Query.AppendEndExpression();
                return;
            }


            if (methodCall.Method.DeclaringType == typeof(Queryable))
            {
                visitor.Query.AppendBeginExpression();
                visitor.Visit(methodCall.Arguments[1]);
                visitor.Query.AppendIn();
                IQueryable query = methodCall.Arguments.First().GetValue() as IQueryable;
                visitor.VisitSubQuery(query.Expression);
                visitor.Query.AppendEndExpression();
                return;
            }

            visitor.Query.AppendBeginExpression();


            visitor.Visit(methodCall.Object);
            visitor.Query.AppendLike();
            visitor.VisitSearchPattern(true, methodCall.Arguments.First(), true);

            visitor.Query.AppendEndExpression();
        }
 private async Task <int> ExecuteCommandAsync(IOqlExpressionVisitor visitor)
 {
     using (IDataSource dataSource = m_data_provider.GetDataSource())
     {
         return(await dataSource.ExecuteCommandAsync(visitor.Query));
     }
 }
Beispiel #6
0
        public override void VisitTo(IOqlExpressionVisitor visitor)
        {
            visitor.Query.AppendInsert().AppendType(visitor.SourceType).AppendBeginExpression();

            Expression        val;
            List <Expression> vals = new List <Expression>();


            IDataChange dc = m_change_set.First();

            val = dc.NewValue;
            visitor.Query.AppendMember(dc.PropertyOrField);


            foreach (IDataChange x in m_change_set.Skip(1))
            {
                visitor.Query.AppendExpressionSeparator();
                visitor.Query.AppendMember(x.PropertyOrField);
            }

            visitor.Query.AppendEndExpression().AppendValues().AppendBeginExpression();

            visitor.Visit(val);

            foreach (Expression x in vals)
            {
                visitor.Query.AppendExpressionSeparator();
                visitor.Visit(x);
            }

            visitor.Query.AppendEndExpression();
        }
 public void FormatMultiply(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(left);
     visitor.Query.AppendMultiply();
     visitor.Visit(right);
     visitor.Query.AppendEndExpression();
 }
 public override void FormatMethodCall(IOqlExpressionVisitor visitor, MethodCallExpression method)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(method.Object);
     visitor.Query.AppendLike();
     visitor.VisitSearchPattern(false, method.Arguments.First(), true);
     visitor.Query.AppendEndExpression();
 }
Beispiel #9
0
 public void FormatGreaterThan(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(left);
     visitor.Query.AppendGreaterThan();
     visitor.Visit(right);
     visitor.Query.AppendEndExpression();
 }
Beispiel #10
0
 public void FormatOr(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(left);
     visitor.Query.AppendOrElse();
     visitor.Visit(right);
     visitor.Query.AppendEndExpression();
 }
Beispiel #11
0
 public void FormatNotEqual(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(left);
     visitor.Query.AppendNotEqual();
     visitor.Visit(right);
     visitor.Query.AppendEndExpression();
 }
 public override void VisitTo(IOqlExpressionVisitor visitor)
 {
     if (m_expression != null)
     {
         visitor.Query.AppendWhere();
         visitor.Visit(m_expression);
     }
 }
Beispiel #13
0
 public void FormatAnd(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(left);
     visitor.Query.AppendAndAlso();
     visitor.Visit(right);
     visitor.Query.AppendEndExpression();
 }
 public void FormatSubtractChecked(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     visitor.Query.AppendBeginExpression();
     visitor.Visit(left);
     visitor.Query.AppendSubtract();
     visitor.Visit(right);
     visitor.Query.AppendEndExpression();
 }
Beispiel #15
0
        public override void VisitTo(IOqlExpressionVisitor visitor)
        {
            if (visit_to_aggregate != null)
            {
                visitor.Query.AppendSelect().AppendBlank();
                visit_to_aggregate(visitor, m_select_expression);
                return;
            }

            if (visitor.Context.CallResult.Command == OqlCommandToken.Scalar)
            {
                visitor.Query.AppendSelect().AppendBlank();
                visitor.Context.AggregateFormatter.FormatCount(visitor);
                return;
            }


            if (visitor.Context.CallResult.Command == OqlCommandToken.IsAny)
            {
                visitor.Query.AppendSelect().AppendTop(1).AppendBlank().AppendMultiply();
                return;
            }

            if (visitor.Context.CallResult.Command == OqlCommandToken.IsAll)
            {
                visitor.Query.AppendSelect().AppendBlank().AppendMultiply();
                return;
            }


            VisitForSelect(visitor);

            if (m_select_expression == null)
            {
                IEnumerable <MemberInfo> members = visitor.SourceType.SelectMembers();

                if (members.Any())
                {
                    visitor.Query.AppendMember(members.First());

                    foreach (MemberInfo x in members.Skip(1))
                    {
                        visitor.Query.AppendExpressionSeparator();
                        visitor.Query.AppendMember(x);
                    }
                }

                return;
            }


            visitor.Visit(m_select_expression);
        }
        public async Task <object> ExecuteAsync(Expression expression)
        {
            IOqlExpressionVisitor visitor = m_data_provider.CreateExpressionVisitor().ExecuteVisit(expression);

            switch (visitor.Context.CallResult.Command)
            {
            case OqlCommandToken.Exec: return(await ExecuteCommandAsync(visitor));

            case OqlCommandToken.Scalar: return(await GetScalarAsync(visitor));

            default:
                return(await ObjectQueryNavigator.CreateResultAsync(visitor.Context.CallResult, m_data_provider.GetDataSource(), visitor.Query));
            }
        }
        public object Execute(Expression expression)
        {
            IOqlExpressionVisitor visitor = m_data_provider.CreateExpressionVisitor().ExecuteVisit(expression);

            switch (visitor.Context.CallResult.Command)
            {
            case OqlCommandToken.Exec: return(ExecuteCommand(visitor));

            case OqlCommandToken.Scalar: return(GetScalar(visitor));

            default:
                return(ObjectQueryNavigator.CreateResult(visitor.Context.CallResult, m_data_provider.GetDataSource(), visitor.Query));
            }
        }
Beispiel #18
0
        public override void VisitTo(IOqlExpressionVisitor visitor)
        {
            if (m_order_stack.Count > 0)
            {
                visitor.Query.AppendOrderBy();

                VisitOrderBy(visitor, m_order_stack.Pop());

                while (m_order_stack.Count > 0)
                {
                    visitor.Query.AppendExpressionSeparator();
                    VisitOrderBy(visitor, m_order_stack.Pop());
                }
            }
        }
Beispiel #19
0
        public override void VisitTo(IOqlExpressionVisitor visitor)
        {
            visitor.Query.AppendUpdate().AppendType(visitor.SourceType).AppendSet();

            IDataChange dc = ChangeSet.First();

            visitor.Query.AppendMember(dc.PropertyOrField).AppendAssign();
            visitor.Visit(dc.NewValue);

            foreach (IDataChange x in ChangeSet.Skip(1))
            {
                visitor.Query.AppendExpressionSeparator().AppendMember(dc.PropertyOrField).AppendAssign();
                visitor.Visit(dc.NewValue);
            }
        }
Beispiel #20
0
        protected virtual void VisitForSelect(IOqlExpressionVisitor visitor)
        {
            visitor.Query.AppendSelect();

            if (m_has_distinct)
            {
                visitor.Query.AppendDistinct();
            }


            int size = visitor.Context.CallResult.Size;

            if (size > 0 && size < int.MaxValue)
            {
                visitor.Query.AppendTop(size);
            }
        }
Beispiel #21
0
        protected virtual void VisitOrderBy(IOqlExpressionVisitor visitor, MethodCallExpression methodCall)
        {
            visitor.Visit(methodCall.GetArgument(1));


            if (methodCall.IsCalledOr(OrderBy, ThenBy))
            {
                visitor.Query.AppendAsc();
                return;
            }


            if (methodCall.IsCalledOr(OrderByDescending, ThenByDescending))
            {
                visitor.Query.AppendDesc();
            }
        }
Beispiel #22
0
        public Expression ProcessMethodCall(IOqlExpressionVisitor caller, MethodCallExpression methodCall)
        {
            IOqlMethodCallEntry methodEntry = base[methodCall];

            if (methodEntry != null)
            {
                IOqlClause clause = methodEntry.Clause;

                if (clause != null)
                {
                    clause.ProcessMethodCall(this, methodCall);
                }

                IOqlMethodCallFormatter formatter = methodEntry.Formatter;

                if (formatter != null)
                {
                    formatter.FormatMethodCall(caller, methodCall);
                    return(methodCall);
                }
            }

            return(caller.Visit(methodCall.Arguments[0]));
        }
 public abstract void FormatMethodCall(IOqlExpressionVisitor visitor, MethodCallExpression method);
 public void FormatNegateChecked(IOqlExpressionVisitor visitor, Expression operand)
 {
     FormatNegate(visitor, operand);
 }
 public void FormatMultiplyAssignChecked(IOqlExpressionVisitor visitor, Expression left, Expression right)
 {
     FormatMultiply(visitor, left, right);
 }
 public void FormatUnaryPlus(IOqlExpressionVisitor visitor, Expression operand)
 {
     visitor.Query.AppendPlus().AppendBeginExpression();
     visitor.Visit(operand);
     visitor.Query.AppendEndExpression();
 }
 public override void VisitTo(IOqlExpressionVisitor visitor)
 {
 }
 public override void VisitTo(IOqlExpressionVisitor visitor)
 {
     visitor.Query.AppendFrom().AppendType(visitor.SourceType);
 }
Beispiel #29
0
 public override void VisitTo(IOqlExpressionVisitor visitor)
 {
     visitor.Query.AppendDelete().AppendBlank();
 }
Beispiel #30
0
 public abstract void VisitTo(IOqlExpressionVisitor visitor);