Ejemplo n.º 1
0
        public override void VisitColumnReference(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            if (_lambdaParameters != null &&
                _lambdaParameters.Count > 0 &&
                _lambdaParameters.Peek().TryGetValue(identifiers.FirstOrDefault(), out var parameterExpression))
            {
                if (identifiers.Count > 1)
                {
                    AddExpressionToStack(MemberUtils.GetSubfieldMember(identifiers, 1, parameterExpression, _visitorMetadata.OperationsProvider));
                }
                else
                {
                    AddExpressionToStack(parameterExpression);
                }

                return;
            }

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);
            var memberAccess = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);

            AddUsedProperty(property);
            AddExpressionToStack(memberAccess);
            AddNameToStack(string.Join(".", identifiers));
        }
Ejemplo n.º 2
0
        public override void VisitColumnReference(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);
            var memberAccess = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);

            _usedProperties.Add(property);

            _groupByExpressions.Add(new GroupByExpression(memberAccess, string.Join(".", identifiers), property));
        }
Ejemplo n.º 3
0
        private VisitResult VisitColumnReferenceExpression_Internal(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);
            var memberAccess = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);

            AddUsedProperty(property);
            return(new VisitResult()
            {
                Expression = memberAccess
            });
        }
Ejemplo n.º 4
0
        public override void VisitInExpression(InExpression inExpression)
        {
            if (inExpression.Values == null)
            {
                throw new SqlErrorException("IN predicate only supports a list of values right now");
            }

            Expression memberExpression;

            if (inExpression.Expression is ColumnReference columnReferenceExpression)
            {
                //Check here if any index can be used aswell

                var identifiers = columnReferenceExpression.Identifiers;

                identifiers      = MemberUtils.RemoveAlias(_previousStage, identifiers);
                memberExpression = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);
                AddUsedProperty(property);
                AddNameToStack(string.Join(".", identifiers));
            }
            else
            {
                throw new SqlErrorException("IN predicate can only be used against column names");
            }

            IList list = ListUtils.GetNewListFunction(memberExpression.Type)();

            foreach (var value in inExpression.Values)
            {
                if (value is Literal literal)
                {
                    list.Add(TypeConvertUtils.ConvertToType(literal.GetValue(), memberExpression.Type));
                }
                else if (value is VariableReference variableReference)
                {
                    var sqlParameter  = _visitorMetadata.Parameters.GetParameter(variableReference.Name);
                    var variableValue = sqlParameter.GetValue(memberExpression.Type);
                    list.Add(variableValue);
                }
                else
                {
                    throw new SqlErrorException("IN predicate only supports literal or parameter values.");
                }
            }
            var inPredicate = _visitorMetadata.OperationsProvider.GetListContains(memberExpression, list);

            AddExpressionToStack(inPredicate);
        }