コード例 #1
0
        public virtual void Visit(ListExpression op)
        {
            Writer.Write('(');
            var first = true;

            foreach (var arg in op.Values)
            {
                if (!first)
                {
                    Writer.Write(", ");
                }
                first = false;
                arg.Visit(this);
            }
            Writer.Write(')');
        }
コード例 #2
0
 void IExpressionVisitor.Visit(ListExpression op)
 {
     throw new NotSupportedException();
 }
コード例 #3
0
        internal IExpression Parse(QueryItem table, IPropertyDefinition prop, string value, Condition condition = Condition.Undefined)
        {
            var propRef = new PropertyReference(prop.NameProp().Value
                                                ?? prop.KeyedName().Value
                                                ?? prop.IdProp().KeyedName().Value, table);
            var meta = prop.Metadata();

            if (meta.DataType().Value == "item")
            {
                propRef = new PropertyReference("keyed_name", propRef.GetOrAddTable(table.Context));
            }

            var expressions = new List <IExpression>();
            var values      = default(IEnumerable <string>);

            switch (condition)
            {
            case Condition.Undefined:
            case Condition.Equal:
            case Condition.NotEqual:
            case Condition.Like:
            case Condition.NotLike:
                values = SplitOr(value);
                break;

            default:
                values = new[] { value };
                break;
            }

            foreach (var val in values)
            {
                if ((val == "*" || (val == "%" && String.IsPercentWildcard)) && condition == Condition.Undefined)
                {
                    expressions.Add(new LikeOperator()
                    {
                        Left  = propRef,
                        Right = AmlLikeParser.Instance.Parse("%")
                    }.Normalize());
                }
                else if (condition == Condition.IsNotNull)
                {
                    return(new IsOperator()
                    {
                        Left = propRef,
                        Right = IsOperand.NotNull
                    }.Normalize());
                }
                else if (condition == Condition.IsNull)
                {
                    return(new IsOperator()
                    {
                        Left = propRef,
                        Right = IsOperand.Null
                    }.Normalize());
                }
                else
                {
                    switch (meta.DataType().AsString("").ToLowerInvariant())
                    {
                    case "boolean":
                        expressions.Add(Boolean.Parse(propRef, val, condition));
                        break;

                    case "date":
                        expressions.Add(Date.Parse(propRef, val, condition));
                        break;

                    case "decimal":
                    case "float":
                    case "integer":
                        expressions.Add(Number.Parse(propRef, val, condition));
                        break;

                    default:
                        expressions.Add(String.Parse(propRef, val, condition));
                        break;
                    }
                }
            }

            var addNotOperator = expressions.Count > 0 && expressions.All(e => e is NotOperator);

            if (addNotOperator)
            {
                expressions = expressions.Cast <NotOperator>().Select(n => n.Arg).ToList();
            }

            var result = default(IExpression);

            if (expressions.Count > 0 && expressions.All(e => e is EqualsOperator eq && eq.Right is IOperand))
            {
                var list = new ListExpression();
                foreach (var op in expressions.Cast <EqualsOperator>().Select(e => (IOperand)e.Right))
                {
                    list.Values.Add(op);
                }
                result = new InOperator()
                {
                    Left  = propRef,
                    Right = list
                }.Normalize();
            }
コード例 #4
0
 void IExpressionVisitor.Visit(ListExpression op)
 {
     _clone = Clone(op);
 }
コード例 #5
0
        /// <summary>Closes one element and pops the corresponding namespace scope.</summary>
        /// <exception cref="InvalidOperationException">This results in an invalid XML document.</exception>
        /// <exception cref="InvalidOperationException">An <see cref="XmlWriter" /> method was called before a previous asynchronous operation finished. In this case, <see cref="InvalidOperationException" /> is thrown with the message “An asynchronous operation is already in progress.”</exception>
        public override void WriteEndElement()
        {
            if (_stack.Count > 0)
            {
                var value = _buffer.ToString() ?? "";
                _buffer.Length = 0;

                var last = _stack.Pop();
                if (_attrBuffer.TryGetValue(ParameterSubstitution.DateRangeAttribute, out var dateRange) &&
                    ParameterSubstitution.TryDeserializeDateRange(dateRange, out var dateStart, out var dateEnd) &&
                    (dateStart.HasValue || dateEnd.HasValue))
                {
                    var property = (last as BinaryOperator)?.Left ?? (last as BetweenOperator)?.Left;
                    if (property == null)
                    {
                        throw new NotSupportedException();
                    }

                    if (dateStart.HasValue && dateEnd.HasValue)
                    {
                        last = new BetweenOperator()
                        {
                            Left = property,
                            Min  = new DateOffsetLiteral(_context, dateStart.Value, false),
                            Max  = new DateOffsetLiteral(_context, dateEnd.Value, true),
                        }.Normalize();
                    }
                    else if (dateStart.HasValue)
                    {
                        last = new GreaterThanOrEqualsOperator()
                        {
                            Left  = property,
                            Right = new DateOffsetLiteral(_context, dateStart.Value, false)
                        }.Normalize();
                    }
                    else
                    {
                        last = new LessThanOrEqualsOperator()
                        {
                            Left  = property,
                            Right = new DateOffsetLiteral(_context, dateEnd.Value, true)
                        }.Normalize();
                    }
                }
                else
                {
                    if (last is IsOperator isOp)
                    {
                        switch (value)
                        {
                        case "defined":
                            isOp.Right = IsOperand.Defined;
                            break;

                        case "not defined":
                            isOp.Right = IsOperand.NotDefined;
                            break;

                        case "not null":
                            isOp.Right = IsOperand.NotNull;
                            break;

                        case "null":
                            isOp.Right = IsOperand.Null;
                            break;

                        case "":
                            break;

                        default:
                            throw new NotSupportedException();
                        }
                    }
                    else if (last is InOperator inOp)
                    {
                        inOp.Right = ListExpression.FromSqlInClause(value);
                    }
                    else if (last is BetweenOperator betweenOp)
                    {
                        betweenOp.SetMinMaxFromSql(value);
                    }
                    else if (last is PropertyReference property)
                    {
                        if (_stack.OfType <Join>().Last().Right.Joins.Any(j => j.Right.TypeProvider == property))
                        {
                            last = null;
                        }
                        else
                        {
                            last = new EqualsOperator()
                            {
                                Left = property
                            };
                        }
                    }

                    if (!(last is ILogical) && last is BinaryOperator binOp)
                    {
                        if (value == "__now()")
                        {
                            binOp.Right = new Functions.CurrentDateTime();
                        }
                        else if (binOp is LikeOperator)
                        {
                            binOp.Right = AmlLikeParser.Instance.Parse(value);
                        }
                        else
                        {
                            binOp.Right = NormalizeLiteral((PropertyReference)binOp.Left, value, _context);
                        }
                    }
                }

                if (last is BinaryOperator genOp &&
                    genOp.Left is PropertyReference prop &&
                    (prop.Name == "generation" || prop.Name == "id"))
                {
                    Query.Version = new VersionCriteria()
                    {
                        Condition = genOp
                    };
                    if (prop.Name == "id")
                    {
                        AddToCondition(genOp);
                    }
                }