Ejemplo n.º 1
0
        private static AnalyzeResult Analyze(IDatabaseProvider provider, AnalyzeResult previousAnalyze, MethodCallExpression expression)
        {
            switch (expression.Method.Name)
            {
            case "CompareString":
            {
                var analyzeResult = new AnalyzeResult(Analyze(provider, previousAnalyze, expression.Arguments[0]).ParameterName, Analyze(provider, previousAnalyze, expression.Arguments[1]).ParameterValue);
                analyzeResult.SetParameterCombination(analyzeResult.ParameterName, analyzeResult.ParameterValue);
                //analyzeResult.SetSql(analyzeResult.ParameterName + " = " + provider.CreateParameterName(analyzeResult.ParameterName));
                return(analyzeResult);
            }
            }

            /*var arguments = new object[expression.Arguments.Count];
             * for(int i = 0; i< expression.Arguments.Count; i++)
             * {
             *  var argumentAnalyzeResult = Analyze(provider, previousAnalyze, expression.Arguments[i]);
             *  arguments[i] = argumentAnalyzeResult.ParameterName != null ? argumentAnalyzeResult.ParameterName:  argumentAnalyzeResult.ParameterValue;
             * }
             * var result = expression.Method.Invoke(expression.Object, arguments);*/

            //var analyzeResult = Analyze(provider, previousAnalyze, expression.Object);

            throw new NotImplementedException("Method '" + expression.Method.Name + "' in Analyze Call is not implemented");
        }
Ejemplo n.º 2
0
        private static AnalyzeResult Analyze(IDatabaseProvider provider, AnalyzeResult previousAnalyze, BinaryExpression expression)
        {
            var analyzeLeft  = Analyze(provider, previousAnalyze, expression.Left);
            var analyzeRight = Analyze(provider, analyzeLeft, expression.Right);

            var leftSql = analyzeLeft.GetSql();

            if (leftSql == null)
            {
                leftSql = analyzeLeft.ParameterName;
            }
            var rightSql = analyzeRight.GetSql();

            if (rightSql == null)
            {
                rightSql = provider.CreateParameterName(analyzeLeft.ParameterName);
            }

            var analyzeResult = new AnalyzeResult(analyzeLeft, analyzeRight);

            if (!analyzeLeft.HasParameterCombination && !analyzeRight.HasParameterCombination)
            {
                analyzeResult.SetParameterCombination(analyzeLeft.ParameterName, analyzeRight.ParameterValue);
            }

            switch (expression.NodeType)
            {
            case ExpressionType.Equal:
                if (analyzeRight.ParameterValue == null)
                {
                    analyzeResult.SetSql(leftSql + " is null");
                }
                else
                {
                    analyzeResult.SetSql(leftSql + " = " + rightSql);
                }
                break;

            case ExpressionType.NotEqual:
                if (analyzeRight.ParameterValue == null)
                {
                    analyzeResult.SetSql(leftSql + " is not null");
                }
                else
                {
                    analyzeResult.SetSql(leftSql + " <> " + rightSql);
                }
                break;

            case ExpressionType.GreaterThan:
                analyzeResult.SetSql(leftSql + " > " + rightSql);
                break;

            case ExpressionType.GreaterThanOrEqual:
                analyzeResult.SetSql(leftSql + " >= " + rightSql);
                break;

            case ExpressionType.LessThan:
                analyzeResult.SetSql(leftSql + " < " + rightSql);
                break;

            case ExpressionType.LessThanOrEqual:
                analyzeResult.SetSql(leftSql + " <= " + rightSql);
                break;

            case ExpressionType.AndAlso:
            case ExpressionType.And:
                analyzeResult.SetSql("(" + leftSql + ") and (" + rightSql + ")");
                break;

            case ExpressionType.OrElse:
            case ExpressionType.Or:
                analyzeResult.SetSql("(" + leftSql + ") or (" + rightSql + ")");
                break;

            default:
                return(null);
            }

            return(analyzeResult);
        }