Example #1
0
        private static string ToCommand(QueryExpression exp, Dictionary<string, object> parameters)
        {
            StringBuilder sb = new StringBuilder();
            if (exp.Negated)
                sb.Append("NOT ");
            switch (exp.Type)
            {
                case ExpressionType.Complex:
                    if (exp.LeftExpression == null || exp.RightExpression == null)
                        throw new ArgumentException("A complex expression must have a LeftExpression, RightExpression and Operand.");
                    
                    sb.Append("(");
                    sb.Append(ToCommand(exp.LeftExpression, parameters));
                    sb.Append(" ");
                    sb.Append(exp.Operand.ToString());
                    sb.Append(" ");
                    sb.Append(ToCommand(exp.RightExpression, parameters));
                    sb.Append(")");
                    break;
                case ExpressionType.Null:
                    if (exp.FieldName == null)
                        throw new ArgumentException("The FieldName must be set in order to do a null comparison.");
                    
                    sb.Append(exp.FieldName);
                    sb.Append(" IS NULL");
                    break;
                case ExpressionType.String:
                case ExpressionType.Numeric:
                    if (string.IsNullOrEmpty(exp.FieldName) || !exp.Operator.HasValue || string.IsNullOrEmpty(exp.Value))
                        throw new ArgumentException("The FieldName, Operator, and Value must be set in order to evaluate the expression.");
                    if (exp.Type == ExpressionType.Numeric)
                    {
                        float test;
                        if (!float.TryParse(exp.Value, out test))
                            throw new ArgumentException("The value for the Numeric Expression is not numeric.");
                    }

                    string paramName = UniqueParameterName(exp.FieldName, parameters);
                    string value = GetValueSql(exp.Value, exp.Operator.Value);
                    sb.Append(exp.FieldName);
                    sb.Append(" ");
                    sb.Append(GetOperatorSql(exp.Operator.Value));
                    sb.Append(" ");
                    sb.Append(paramName);
                    parameters.Add(paramName, exp.Value);
                    break;
            }
            return sb.ToString();
        }
Example #2
0
 internal QueryExpression(QueryExpression FirstExpression, QueryOperand Operand, QueryExpression SecondExpression)
 {
     this.Type = ExpressionType.Complex;
     this.LeftExpression = FirstExpression;
     this.Operand = Operand;
     this.RightExpression = SecondExpression;
 }
Example #3
0
        public QueryObject(string TableName, QueryExpression Filters, List<SortObject> Sorts, int PageSize, int Offset)
        {

        }
Example #4
0
 internal QueryExpression(bool Negated, ExpressionType Type, string FieldName, Operator? Operator, string Value, QueryExpression LeftExpression, QueryOperand Operand, QueryExpression RightExpression)
 {
     this.Negated = Negated;
     this.Type = Type;
     this.FieldName = FieldName;
     this.Operator = Operator;
     this.Value = Value;
     this.LeftExpression = LeftExpression;
     this.Operand = Operand;
     this.RightExpression = RightExpression;
 }