Exemple #1
0
        /// <summary>
        /// Creates an SQL expression based on the literal value. The object value will not be escaped.
        /// </summary>
        private string CreateExpressionString(SqlLiteral literal)
        {
            // Correct Name and define variables
            string fieldName = SQLiteContext.QuoteIdentifier(Identifier, Statement.AttributeQuoteMode, Statement.AttributeQuoteKind);

            switch (ComparisonOperator)
            {
            case Comparison.Equals:
                return($"{fieldName} = {literal.Value}");

            case Comparison.NotEqualTo:
                return($"{fieldName} != {literal.Value}");

            case Comparison.Like:
                return($"{fieldName} LIKE {literal.Value}");

            case Comparison.NotLike:
                return($"{fieldName} NOT LIKE {literal.Value}");

            case Comparison.GreaterThan:
                return($"{fieldName} > {literal.Value}");

            case Comparison.GreaterOrEquals:
                return($"{fieldName} >= {literal.Value}");

            case Comparison.LessThan:
                return($"{fieldName} < {literal.Value}");

            case Comparison.LessOrEquals:
                return($"{fieldName} <= {literal.Value}");

            default:
                string name = Enum.GetName(typeof(Comparison), ComparisonOperator);
                throw new Exception($"Cannot parse operator {name} from an SqlLiteral.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates an SQL expression based on the literal value. The object value will not be escaped.
        /// </summary>
        public static string CreateExpressionString(string fieldName, Comparison @operator, SqlLiteral literal)
        {
            // Correct Name and define variables
            switch (@operator)
            {
            case Comparison.Equals:
                return($"{fieldName} = {literal.Value}");

            case Comparison.NotEqualTo:
                return($"{fieldName} != {literal.Value}");

            case Comparison.Like:
                return($"{fieldName} LIKE {literal.Value}");

            case Comparison.NotLike:
                return($"{fieldName} NOT LIKE {literal.Value}");

            case Comparison.GreaterThan:
                return($"{fieldName} > {literal.Value}");

            case Comparison.GreaterOrEquals:
                return($"{fieldName} >= {literal.Value}");

            case Comparison.LessThan:
                return($"{fieldName} < {literal.Value}");

            case Comparison.LessOrEquals:
                return($"{fieldName} <= {literal.Value}");

            default:
                string name = Enum.GetName(typeof(Comparison), @operator);
                throw new Exception($"Cannot parse operator {name} from an SqlLiteral.");
            }
        }