Expression?MakeSqlValue(Expression?exp)
    {
        if (exp == null)
        {
            return(null !);
        }

        if (!inSql || !IsBooleanExpression(exp))
        {
            return(exp);
        }

        if (exp.NodeType == ExpressionType.Constant)
        {
            switch (((bool?)((ConstantExpression)exp).Value))
            {
            case false: return(new SqlConstantExpression(0, exp.Type));

            case true: return(new SqlConstantExpression(1, exp.Type));

            case null: return(new SqlConstantExpression(null, exp.Type));
            }
        }

        if (!IsSqlCondition(exp))
        {
            return(exp);
        }

        var result = new CaseExpression(new[] { new When(exp, new SqlConstantExpression(true)) }, new SqlConstantExpression(false));

        return(exp.Type.IsNullable() ? result.Nullify() : result);
    }
Beispiel #2
0
        protected override Expression VisitCase(CaseExpression caseExpression)
        {
            Check.NotNull(caseExpression, nameof(caseExpression));

            var parentOptimize = _optimize;

            var testIsCondition = caseExpression.Operand == null;

            _optimize = false;
            var operand     = (SqlExpression)Visit(caseExpression.Operand);
            var whenClauses = new List <CaseWhenClause>();

            foreach (var whenClause in caseExpression.WhenClauses)
            {
                _optimize = testIsCondition;
                var test = (SqlExpression)Visit(whenClause.Test);
                _optimize = false;
                var result = (SqlExpression)Visit(whenClause.Result);
                whenClauses.Add(new CaseWhenClause(test, result));
            }

            _optimize = false;
            var elseResult = (SqlExpression)Visit(caseExpression.ElseResult);

            _optimize = parentOptimize;

            return(ApplyConversion(caseExpression.Update(operand, whenClauses, elseResult), condition: false));
        }
        Expression MakeSqlValue(Expression exp)
        {
            if (exp == null)
                return null;

            if (!inSql || !IsBooleanExpression(exp))
                return exp;

            if (exp.NodeType == ExpressionType.Constant)
            {
                switch (((bool?)((ConstantExpression)exp).Value))
                {
                    case false: return new SqlConstantExpression(0, exp.Type);
                    case true: return new SqlConstantExpression(1, exp.Type);
                    case null: return new SqlConstantExpression(null, exp.Type);
                }
                throw new InvalidOperationException("Entity");
            }

            if (!IsSqlCondition(exp))
                return exp;

            var result =  new CaseExpression(new[] { new When(exp, new SqlConstantExpression(true)) }, new SqlConstantExpression(false));

            return exp.Type.IsNullable() ? result.Nullify() : result;
        }
Beispiel #4
0
    protected internal override Expression VisitCase(CaseExpression cex)
    {
        AppendNewLine(Indentation.Inner);
        sb.Append("CASE");
        AppendNewLine(Indentation.Inner);
        for (int i = 0, n = cex.Whens.Count; i < n; i++)
        {
            When when = cex.Whens[i];
            sb.Append("WHEN ");
            Visit(when.Condition);
            sb.Append(" THEN ");
            Visit(when.Value);
            AppendNewLine(Indentation.Same);
        }
        if (cex.DefaultValue != null)
        {
            sb.Append("ELSE ");
            Visit(cex.DefaultValue);
            AppendNewLine(Indentation.Outer);
        }
        sb.Append("END");
        AppendNewLine(Indentation.Outer);

        return(cex);
    }
Beispiel #5
0
        protected override Expression VisitCase(CaseExpression caseExpression)
        {
            var parentSearchCondition = _isSearchCondition;

            var testIsCondition = caseExpression.Operand == null;

            _isSearchCondition = false;
            var operand     = (SqlExpression)Visit(caseExpression.Operand);
            var whenClauses = new List <CaseWhenClause>();

            foreach (var whenClause in caseExpression.WhenClauses)
            {
                _isSearchCondition = testIsCondition;
                var test = (SqlExpression)Visit(whenClause.Test);
                _isSearchCondition = false;
                var result = (SqlExpression)Visit(whenClause.Result);
                whenClauses.Add(new CaseWhenClause(test, result));
            }

            _isSearchCondition = false;
            var elseResult = (SqlExpression)Visit(caseExpression.ElseResult);

            _isSearchCondition = parentSearchCondition;

            return(ApplyConversion(caseExpression.Update(operand, whenClauses, elseResult), condition: false));
        }
Beispiel #6
0
        private ISqlElement GetFieldExpression(QueryField field, SelectClause selectClause)
        {
            if (field.properties.Length < 1)
            {
                throw new InvalidOperationException("assertion failure");
            }
            if (field.properties.Length == 1)
            {
                return(GetPropertyReference(field.properties[0], selectClause));
            }
            var result       = new CaseExpression();
            var eqConditions = new List <ISqlElement>();

            foreach (var property in field.properties)
            {
                eqConditions.Clear();
                var entity = property.referer;
                while (entity != null)
                {
                    if (entity.unionCondition != null)
                    {
                        eqConditions.Add(entity.unionCondition);
                    }
                    entity = entity.referer == null ? null : entity.referer.referer;
                }
                result.Elements.Add(new CaseElement
                {
                    Value     = GetPropertyReference(property, selectClause),
                    Condition = eqConditions.Combine()
                });
            }
            return(result);
        }
        public async Task TestCaseExpression()
        {
            var config = new MustacheConfigSchema()
            {
                Params = new List <Param>
                {
                    new Param {
                        Name = "MySql", DefaultValue = "true"
                    },
                    new Param {
                        Name = "MySqlEFCore", DefaultValue = "false"
                    },
                    new Param {
                        Name = "C", DefaultValue = "false"
                    },
                },
            };
            var dv = new Dictionary <string, string>
            {
                { "TargetFrameworkVersion", "netcoreapp2.2" },
            };
            var calcParam = new CalculatedParam
            {
                Name           = "AspNetCoreVersion",
                Expression     = "TargetFrameworkVersion,netcoreapp2.2=2.2.0,netcoreapp2.1=2.1.1,default=False",
                ExpressionType = ExpressionTypeEnum.Case,
            };

            var expression = new CaseExpression(_logger, calcParam, config);
            var result     = await expression.EvaluateExpressionAsync(dv);

            Assert.Equal("2.2.0", result);
        }
Beispiel #8
0
        /*
         *      BNF:
         * <case expression> ::=
         * case [<expression>]
         *  <ne case item expression commalist>
         *  else <expression>
         * end
         *
         * <case item expression> ::=
         * when <expression> then <expression>
         */
        protected CaseExpression CaseExpression(Lexer lexer)
        {
            lexer.NextToken().CheckSymbol(Keywords.Case);
            CaseExpression caseExpression = new CaseExpression();

            if (!(lexer.PeekTokenSymbol(1) == Keywords.When))
            {
                caseExpression.Expression = Expression(lexer);
            }
            bool done = false;

            do
            {
                caseExpression.CaseItems.Add(CaseItemExpression(lexer));
                switch (lexer[1].AsSymbol)
                {
                case Keywords.When: break;

                case Keywords.Else:
                    caseExpression.ElseExpression = CaseElseExpression(lexer);
                    done = true;
                    break;

                default: throw new ParserException(ParserException.Codes.CaseItemExpressionExpected);
                }
            }while (!done);
            lexer.NextToken().CheckSymbol(Keywords.End);
            return(caseExpression);
        }
        public void Visit(CaseExpression statement)
        {
            var arg = VisitChild(statement.Expression);

            _codeStack.Peek().Tag            = arg.Tag;
            _codeStack.Peek().CodeExpression = arg.CodeExpression;
        }
        private SqlExpression OptimizeCompareTo(
            SqlBinaryExpression sqlBinaryExpression,
            int intValue,
            CaseExpression caseExpression)
        {
            var testLeft     = ((SqlBinaryExpression)caseExpression.WhenClauses[0].Test).Left;
            var testRight    = ((SqlBinaryExpression)caseExpression.WhenClauses[0].Test).Right;
            var operatorType = sqlBinaryExpression.Right is SqlConstantExpression
                ? sqlBinaryExpression.OperatorType
                : sqlBinaryExpression.OperatorType switch
            {
                ExpressionType.GreaterThan => ExpressionType.LessThan,
                ExpressionType.GreaterThanOrEqual => ExpressionType.LessThanOrEqual,
                ExpressionType.LessThan => ExpressionType.GreaterThan,
                ExpressionType.LessThanOrEqual => ExpressionType.GreaterThanOrEqual,
                _ => sqlBinaryExpression.OperatorType
            };

            switch (operatorType)
            {
            // CompareTo(a, b) != 0 -> a != b
            // CompareTo(a, b) != 1 -> a <= b
            // CompareTo(a, b) != -1 -> a >= b
            case ExpressionType.NotEqual:
                return((SqlExpression)Visit(intValue switch
                {
                    0 => _sqlExpressionFactory.NotEqual(testLeft, testRight),
                    1 => _sqlExpressionFactory.LessThanOrEqual(testLeft, testRight),
                    _ => _sqlExpressionFactory.GreaterThanOrEqual(testLeft, testRight),
                }));
Beispiel #11
0
        public override void Accept(MatchExpression match)
        {
            AstNode value = match.Children [0];

            value.Visit(this);
            int temporary = methodBuilder.CreateTemporary();

            methodBuilder.EmitInstruction(match.Location, Opcode.StoreLocal, temporary);
            PatternCompiler compiler = new PatternCompiler(symbolTable, methodBuilder,
                                                           temporary,
                                                           this);
            IodineLabel nextLabel = methodBuilder.CreateLabel();
            IodineLabel endLabel  = methodBuilder.CreateLabel();

            for (int i = 1; i < match.Children.Count; i++)
            {
                if (i > 1)
                {
                    methodBuilder.MarkLabelPosition(nextLabel);
                    nextLabel = methodBuilder.CreateLabel();
                }
                CaseExpression clause = match.Children [i] as CaseExpression;
                clause.Pattern.Visit(compiler);
                methodBuilder.EmitInstruction(match.Location, Opcode.JumpIfFalse, nextLabel);
                if (clause.Condition != null)
                {
                    clause.Condition.Visit(this);
                    methodBuilder.EmitInstruction(match.Location, Opcode.JumpIfFalse, nextLabel);
                }
                clause.Value.Visit(this);
                methodBuilder.EmitInstruction(match.Location, Opcode.Jump, endLabel);
            }
            methodBuilder.MarkLabelPosition(endLabel);
        }
        private bool IsCompareTo(CaseExpression caseExpression)
        {
            if (caseExpression != null &&
                caseExpression.Operand == null &&
                caseExpression.ElseResult == null &&
                caseExpression.WhenClauses.Count == 3 &&
                caseExpression.WhenClauses.All(c => c.Test is SqlBinaryExpression &&
                                               c.Result is SqlConstantExpression constant &&
                                               constant.Value is int))
            {
                var whenClauses = caseExpression.WhenClauses.Select(c => new
                {
                    test        = (SqlBinaryExpression)c.Test,
                    resultValue = (int)((SqlConstantExpression)c.Result).Value
                }).ToList();

                if (whenClauses[0].test.Left.Equals(whenClauses[1].test.Left) &&
                    whenClauses[1].test.Left.Equals(whenClauses[2].test.Left) &&
                    whenClauses[0].test.Right.Equals(whenClauses[1].test.Right) &&
                    whenClauses[1].test.Right.Equals(whenClauses[2].test.Right) &&
                    whenClauses[0].test.OperatorType == ExpressionType.Equal &&
                    whenClauses[1].test.OperatorType == ExpressionType.GreaterThan &&
                    whenClauses[2].test.OperatorType == ExpressionType.LessThan &&
                    whenClauses[0].resultValue == 0 &&
                    whenClauses[1].resultValue == 1 &&
                    whenClauses[2].resultValue == -1)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #13
0
        protected override Expression VisitCase(CaseExpression caseExpression)
        {
            Check.NotNull(caseExpression, nameof(caseExpression));

            _isNullable = false;
            // if there is no 'else' there is a possibility of null, when none of the conditions are met
            // otherwise the result is nullable if any of the WhenClause results OR ElseResult is nullable
            var isNullable = caseExpression.ElseResult == null;

            var canOptimize     = _canOptimize;
            var testIsCondition = caseExpression.Operand == null;

            _canOptimize = false;
            var newOperand     = (SqlExpression)Visit(caseExpression.Operand);
            var newWhenClauses = new List <CaseWhenClause>();

            foreach (var whenClause in caseExpression.WhenClauses)
            {
                _canOptimize = testIsCondition;
                var newTest = (SqlExpression)Visit(whenClause.Test);
                _canOptimize = false;
                _isNullable  = false;
                var newResult = (SqlExpression)Visit(whenClause.Result);
                isNullable |= _isNullable;
                newWhenClauses.Add(new CaseWhenClause(newTest, newResult));
            }

            _canOptimize = false;
            var newElseResult = (SqlExpression)Visit(caseExpression.ElseResult);

            _isNullable |= isNullable;
            _canOptimize = canOptimize;

            return(caseExpression.Update(newOperand, newWhenClauses, newElseResult));
        }
Beispiel #14
0
        protected string FormatCaseElseExpression(int offset, CaseExpression caseSwitch)
        {
            StringBuilder sql = new StringBuilder(GetIndent(true) + "ELSE");

            using (new IndentScope(this))
            {
                sql.Append(GetIndent(true) + caseSwitch.Else.FormattedValue(offset, this));
            }

            return(sql.ToString());
        }
Beispiel #15
0
        public override void Accept(CaseExpression caseExpr)
        {
            PatternAnalyzer analyzer = new PatternAnalyzer(errorLog, symbolTable, this);

            caseExpr.Pattern.Visit(analyzer);
            if (caseExpr.Condition != null)
            {
                caseExpr.Condition.Visit(this);
            }
            caseExpr.Value.Visit(this);
        }
    protected internal virtual Expression VisitCase(CaseExpression cex)
    {
        var newWhens   = Visit(cex.Whens, w => VisitWhen(w));
        var newDefault = Visit(cex.DefaultValue);

        if (newWhens != cex.Whens || newDefault != cex.DefaultValue)
        {
            return(new CaseExpression(newWhens, newDefault));
        }
        return(cex);
    }
Beispiel #17
0
 public virtual CaseExpression VisitCase(CaseExpression expression)
 {
     foreach (var element in expression.Elements)
     {
         element.Condition = Visit(element.Condition);
         element.Value     = Visit(element.Value);
     }
     if (expression.DefaultValue != null)
     {
         expression.DefaultValue = Visit(expression.DefaultValue);
     }
     return(expression);
 }
        public virtual Expression VisitCaseExpression(CaseExpression caseExpression)
        {
            _sql.AppendLine("CASE WHEN (");

            using (_sql.Indent())
            {
                VisitExpression(caseExpression.When);
            }

            _sql.Append(") THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END");

            return(caseExpression);
        }
        protected override Expression VisitExtension(Expression extensionExpression)
        {
            Check.NotNull(extensionExpression, nameof(extensionExpression));

            return(extensionExpression switch
            {
                ShapedQueryExpression shapedQueryExpression => VisitShapedQueryExpression(shapedQueryExpression),
                CaseExpression caseExpression => VisitCase(caseExpression),
                SelectExpression selectExpression => VisitSelect(selectExpression),
                InnerJoinExpression innerJoinExpression => VisitInnerJoin(innerJoinExpression),
                LeftJoinExpression leftJoinExpression => VisitLeftJoin(leftJoinExpression),
                _ => base.VisitExtension(extensionExpression),
            });
Beispiel #20
0
        protected override Expression VisitCase(CaseExpression caseExpression)
        {
            Visit(caseExpression.Operand);
            foreach (var whenClause in caseExpression.WhenClauses)
            {
                Visit(whenClause.Test);
                Visit(whenClause.Result);
            }

            if (caseExpression.ElseResult != null)
            {
                Visit(caseExpression.ElseResult);
            }
            return(caseExpression);
        }
Beispiel #21
0
        public bool isCatched(string value, SwitchCaseExpression sce, bool preCatch)
        {
            if (sce is CaseExpression)
            {
                CaseExpression cExp = (CaseExpression)sce;

                if (cExp.next == null)
                {
                    if (preCatch)
                    {
                        evalExpression(cExp.body);
                        return(true);
                    }

                    //if (!cExp.literal.value.stringValue.Equals(value) && !preCatch)
                    if (!cExp.literal.value.stringValue.Equals(value))
                    {
                        return(false);
                    }
                    else
                    {
                        evalExpression(cExp.body);
                        return(true);
                    }
                }
                else
                {
                    if (preCatch)
                    {
                        return(isCatched(value, cExp.next, preCatch));
                    }

                    if (cExp.literal.value.stringValue.Equals(value))
                    {
                        return(isCatched(value, cExp.next, true));
                    }

                    return(isCatched(value, cExp.next, preCatch));
                }
            }
            else if (sce is DefaultExpression)
            {
                evalExpression(((DefaultExpression)sce).body);
                return(true);
            }

            return(false);
        }
        private SqlExpression ApplyTypeMappingOnCase(
            CaseExpression caseExpression, RelationalTypeMapping typeMapping)
        {
            var whenClauses = new List<CaseWhenClause>();
            foreach (var caseWhenClause in caseExpression.WhenClauses)
            {
                whenClauses.Add(
                    new CaseWhenClause(
                        caseWhenClause.Test,
                        ApplyTypeMapping(caseWhenClause.Result, typeMapping)));
            }

            var elseResult = ApplyTypeMapping(caseExpression.ElseResult, typeMapping);

            return caseExpression.Update(caseExpression.Operand, whenClauses, elseResult);
        }
Beispiel #23
0
        public bool isCatched(int value, SwitchCaseExpression sce, bool preCatch)
        {
            if (sce is CaseExpression)
            {
                CaseExpression cExp = (CaseExpression)sce;

                if (cExp.next == null)
                {
                    if (preCatch)
                    {
                        evalExpression(cExp.body);
                        return(true);
                    }

                    if (cExp.literal.value.intValue != value && !preCatch)
                    {
                        return(false);
                    }
                    else
                    {
                        evalExpression(cExp.body);
                        return(true);
                    }
                }
                else
                {
                    if (preCatch)
                    {
                        return(isCatched(value, cExp.next, preCatch));
                    }

                    if (cExp.literal.value.intValue == value)
                    {
                        return(isCatched(value, cExp.next, true));
                    }

                    return(isCatched(value, cExp.next, preCatch));
                }
            }
            else if (sce is DefaultExpression)
            {
                evalExpression(((DefaultExpression)sce).body);
                return(true);
            }

            return(false);
        }
Beispiel #24
0
        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            CaseExpression c = (CaseExpression)node;

            compiler.CompileNode(c.Value, parent.CreateChild(node));
            compiler.AppendLine("$_caseval = array_pop($_stack);");

            foreach (var when in c.WhenClauses)
            {
                var sb = new StringBuilder();
                compiler.AppendLine("$_comparisons = array();");
                foreach (var compar in when.Comparisons)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(" || ");
                    }
                    sb.Append("_isTruthy(array_pop($_comparisons))");
                    compiler.CompileNode(compar, parent.CreateChild(node).CreateChild(when));
                    compiler.AppendLine("$_comparisons[] = array_pop($_stack)->__operator_stricteq(NULL, $_caseval);");
                }
                compiler.AppendLine("if({0})", sb.ToString());
                compiler.AppendLine("{");
                compiler.Indent();
                foreach (var stmt in when.Statements)
                {
                    compiler.CompileNode(stmt, parent.CreateChild(node).CreateChild(when));
                }
                compiler.Dedent();
                compiler.AppendLine("}");
                compiler.AppendLine("else");
                compiler.AppendLine("{");
                compiler.Indent();
            }
            if (c.ElseStatements != null)
            {
                foreach (var stmt in c.ElseStatements)
                {
                    compiler.CompileNode(stmt, parent.CreateChild(node));
                }
            }
            for (int i = 0; i < c.WhenClauses.Length; i++)
            {
                compiler.Dedent();
                compiler.AppendLine("}");
            }
        }
Beispiel #25
0
        private static WhenClause MatchingClause(CaseExpression expr, IArgument arg, Scope scope)
        {
            switch (expr)
            {
            case SimpleCaseExpression simple:
                var input = Evaluate(simple.InputExpression, arg, scope);
                return(simple.WhenClauses
                       .FirstOrDefault(x => Equality.Equal(input, Evaluate(x.WhenExpression, arg, scope))));

            case SearchedCaseExpression searched:
                return(searched.WhenClauses
                       .FirstOrDefault(x => Evaluate(x.WhenExpression, arg, scope)));

            default:
                throw FeatureNotSupportedException.Subtype(expr);
            }
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual Expression Translate(MethodCallExpression methodCallExpression)
        {
            var method = methodCallExpression.Method.OnInterface(typeof(IGeometry));

            if (_methodToFunctionName.TryGetValue(method, out var functionName))
            {
                Expression newExpression = new SqlFunctionExpression(
                    functionName,
                    methodCallExpression.Type,
                    new[] { methodCallExpression.Object }.Concat(methodCallExpression.Arguments));
                if (methodCallExpression.Type == typeof(bool))
                {
                    newExpression = new CaseExpression(
                        new CaseWhenClause(
                            Expression.Not(new IsNullExpression(methodCallExpression.Object)),
                            newExpression));
                }

                return(newExpression);
            }
            if (Equals(method, _getGeometryN))
            {
                return(new SqlFunctionExpression(
                           "GeometryN",
                           methodCallExpression.Type,
                           new[]
                {
                    methodCallExpression.Object,
                    Expression.Add(methodCallExpression.Arguments[0], Expression.Constant(1))
                }));
            }
            if (Equals(method, _isWithinDistance))
            {
                return(Expression.LessThanOrEqual(
                           new SqlFunctionExpression(
                               "Distance",
                               typeof(double),
                               new[] { methodCallExpression.Object, methodCallExpression.Arguments[0] }),
                           methodCallExpression.Arguments[1]));
            }

            return(null);
        }
Beispiel #27
0
 public override CaseExpression VisitCase(CaseExpression expression)
 {
     builder.Append("case");
     foreach (var e in expression.Elements)
     {
         builder.Append("\r\n\t");
         builder.Append("when ");
         Visit(e.Condition);
         builder.Append(" then ");
         Visit(e.Value);
     }
     if (expression.DefaultValue != null)
     {
         builder.Append("\r\n\t");
         builder.Append("else ");
         Visit(expression.DefaultValue);
     }
     builder.Append("\r\nend");
     return(expression);
 }
        public virtual SqlExpression ApplyTypeMapping(SqlExpression sqlExpression, RelationalTypeMapping typeMapping)
        {
            if (sqlExpression == null ||
                sqlExpression.TypeMapping != null)
            {
                return(sqlExpression);
            }

            return(sqlExpression switch
            {
                CaseExpression e => ApplyTypeMappingOnCase(e, typeMapping),
                LikeExpression e => ApplyTypeMappingOnLike(e),
                SqlBinaryExpression e => ApplyTypeMappingOnSqlBinary(e, typeMapping),
                SqlUnaryExpression e => ApplyTypeMappingOnSqlUnary(e, typeMapping),
                SqlConstantExpression e => e.ApplyTypeMapping(typeMapping),
                SqlFragmentExpression e => e,
                SqlFunctionExpression e => e.ApplyTypeMapping(typeMapping),
                SqlParameterExpression e => e.ApplyTypeMapping(typeMapping),
                _ => sqlExpression
            });
        private IDictionary <string, IExpression> GetEvaluationExpressions(MustacheConfigSchema schema)
        {
            var evalExpressions = new Dictionary <string, IExpression>();

            foreach (var calculatedParam in schema.CalculatedParams)
            {
                IExpression expression = null;
                switch (calculatedParam.ExpressionType)
                {
                case ExpressionTypeEnum.Any:
                    expression = new AnyExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.Bool:
                    expression = new BooleanExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.Case:
                    expression = new CaseExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.String:
                    expression = new CaseExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.MoreThanOne:
                    expression = new MoreThanOneExpression(_logger, calculatedParam, schema);
                    break;

                default:
                    throw new InvalidEnumArgumentException("Calculated Expression", (int)calculatedParam.ExpressionType, typeof(ExpressionTypeEnum));
                }

                if (expression != null)
                {
                    evalExpressions.Add(calculatedParam.Name, expression);
                }
            }

            return(evalExpressions);
        }
Beispiel #30
0
        public void addCase(SwitchCaseExpression ce)
        {
            if (cases == null)
            {
                cases = new List <SwitchCaseExpression>();
            }

            cases.Add(ce);

            if (ce is DefaultExpression)
            {
                hasDefaultCase = true;
                return;
            }

            if (ce is CaseExpression)
            {
                SwitchCaseExpression tmp = ce;

                while (tmp != null)
                {
                    if (tmp is DefaultExpression)
                    {
                        hasDefaultCase = true;
                        return;
                    }
                    else
                    {
                        CaseExpression caseExp = (CaseExpression)tmp;

                        if (intCases == null)
                        {
                            intCases = new List <int>();
                        }

                        intCases.Add(caseExp.literal.value.intValue);
                        tmp = caseExp.next;
                    }
                }
            }
        }
        protected override Expression VisitCase(CaseExpression caseExpression)
        {
            caseExpression.ThrowIfNull(nameof(caseExpression));

            Sql.Append("ICASE(");

            if (caseExpression.Operand != null)
            {
                Sql.Append(" ");
                Visit(caseExpression.Operand);
            }

            var first = true;

            foreach (var whenClause in caseExpression.WhenClauses)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Sql.Append(",");
                }

                Visit(whenClause.Test);
                Sql.Append(",");
                Visit(whenClause.Result);
            }

            if (caseExpression.ElseResult != null)
            {
                Sql.Append(",");
                Visit(caseExpression.ElseResult);
            }

            Sql.Append(")");

            return(caseExpression);
        }
Beispiel #32
0
        protected override Expression VisitCase(CaseExpression cex)
        {
            AppendNewLine(Indentation.Inner);
            sb.Append("CASE");
            AppendNewLine(Indentation.Inner);
            for (int i = 0, n = cex.Whens.Count; i < n; i++)
            {
                When when = cex.Whens[i]; 
                sb.Append("WHEN ");
                Visit(when.Condition);
                sb.Append(" THEN ");
                Visit(when.Value);
                AppendNewLine(Indentation.Same); 
            }
            if (cex.DefaultValue != null)
            {
                sb.Append("ELSE ");
                Visit(cex.DefaultValue);
                AppendNewLine(Indentation.Outer);
            }
            sb.Append("END");
            AppendNewLine(Indentation.Outer);

            return cex; 
        }
        protected virtual Expression VisitCase(CaseExpression cex)
        {
            var newWhens = cex.Whens.NewIfChange(w => VisitWhen(w));
            var newDefault = Visit(cex.DefaultValue);

            if (newWhens != cex.Whens || newDefault != cex.DefaultValue)
                return new CaseExpression(newWhens, newDefault);
            return cex;
        }
Beispiel #34
0
        protected override Expression VisitCase(CaseExpression cex)
        {
            var newWhens = cex.Whens.NewIfChange(w => VisitWhen(w));
            var newDefault = MakeSqlValue(Visit(cex.DefaultValue));

            if (newWhens != cex.Whens || newDefault != cex.DefaultValue)
                return new CaseExpression(newWhens, newDefault);
            return cex;
        }
 public override void ExplicitVisit(CaseExpression fragment)
 {
     _fragments.Add(fragment);
 }
Beispiel #36
0
 public override void ExplicitVisit(CaseExpression node) { this.action(node); }