コード例 #1
0
ファイル: Program.cs プロジェクト: ssickles/archive
        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();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ssickles/archive
 internal QueryExpression(QueryExpression FirstExpression, QueryOperand Operand, QueryExpression SecondExpression)
 {
     this.Type = ExpressionType.Complex;
     this.LeftExpression = FirstExpression;
     this.Operand = Operand;
     this.RightExpression = SecondExpression;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: ssickles/archive
        public QueryObject(string TableName, QueryExpression Filters, List<SortObject> Sorts, int PageSize, int Offset)
        {

        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ssickles/archive
 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;
 }