コード例 #1
0
        public void WhereClauseParse04()
        {
            var expr  = SqlWhereParser.Parse("(prop = 'value' OR [User].owned_by_id = 'first') and [User].managed_by_id = 'another'", _table);
            var andOp = expr as AndOperator;

            Assert.IsNotNull(andOp);
            Assert.IsInstanceOfType(andOp.Left, typeof(OrOperator));
            Assert.IsInstanceOfType(andOp.Right, typeof(EqualsOperator));
        }
コード例 #2
0
        public void WhereClauseParse02()
        {
            var expr  = SqlWhereParser.Parse("not [User].owned_by_id >= 'first' and [User].managed_by_id <> 'another'", _table);
            var andOp = expr as AndOperator;

            Assert.IsNotNull(andOp);
            Assert.IsInstanceOfType(andOp.Left, typeof(LessThanOperator));
            Assert.IsInstanceOfType(andOp.Right, typeof(NotEqualsOperator));
        }
コード例 #3
0
        public void WhereClauseParse06()
        {
            var expr = SqlWhereParser.Parse("prop like 'val%' OR [User].owned_by_id is null", _table);
            var orOp = expr as OrOperator;

            Assert.IsNotNull(orOp);
            Assert.IsInstanceOfType(orOp.Left, typeof(LikeOperator));

            var isOp = orOp.Right as IsOperator;

            Assert.IsNotNull(isOp);
            Assert.AreEqual(IsOperand.Null, isOp.Right);
        }
コード例 #4
0
        public void WhereClauseParse10()
        {
            var expr = SqlWhereParser.Parse("SUBSTRING(C_PHONE,1,2) IN ('13', '31', '23', '29', '30', '18', '17')", _table);
            var inOp = expr as InOperator;

            Assert.IsNotNull(inOp);
            Assert.AreEqual(7, inOp.Right.Values.Count);

            var func = inOp.Left as Functions.Substring_One;

            Assert.IsNotNull(func);
            Assert.AreEqual(3, func.Args.Count());
        }
コード例 #5
0
        public void WhereClauseParse07()
        {
            var expr  = SqlWhereParser.Parse("O_ORDERDATE >= '1993-07-01' AND O_ORDERDATE < dateadd(mm,3, '1993-07-01')", _table);
            var andOp = expr as AndOperator;

            Assert.IsNotNull(andOp);
            Assert.IsInstanceOfType(andOp.Left, typeof(GreaterThanOrEqualsOperator));

            var ltOp = andOp.Right as LessThanOperator;

            Assert.IsNotNull(ltOp);

            var func = ltOp.Right as Functions.AddMonths;

            Assert.IsNotNull(func);
        }
コード例 #6
0
        public void WhereClauseParse09()
        {
            var expr  = SqlWhereParser.Parse("L_SHIPDATE >= '1994-01-01' AND L_DISCOUNT NOT BETWEEN .06 - 0.01 AND .06 + 0.01 AND L_QUANTITY < 24", _table);
            var andOp = expr as AndOperator;

            Assert.IsNotNull(andOp);
            Assert.IsInstanceOfType(andOp.Right, typeof(LessThanOperator));

            andOp = andOp.Left as AndOperator;
            Assert.IsNotNull(andOp);
            Assert.IsInstanceOfType(andOp.Left, typeof(GreaterThanOrEqualsOperator));

            var between = (andOp.Right as NotOperator)?.Arg as BetweenOperator;

            Assert.IsNotNull(between);
            Assert.AreEqual(0, Math.Abs(Math.Round((between.Min as FloatLiteral).Value - 0.05, 12)));
            Assert.AreEqual(0, Math.Abs(Math.Round((between.Max as FloatLiteral).Value - 0.07, 12)));
        }
コード例 #7
0
        public void WhereClauseParse03()
        {
            var expr = SqlWhereParser.Parse("created_on > getdate() and [User].owned_by_id in ('first', 'second', 'third', 'fourth')", _table);

            var andOp = expr as AndOperator;

            Assert.IsNotNull(andOp);
            var gtOp = andOp.Left as GreaterThanOperator;

            Assert.IsNotNull(gtOp);
            var func = gtOp.Right as FunctionExpression;

            Assert.IsNotNull(func);
            Assert.AreEqual("getdate", func.Name);

            var inOp = andOp.Right as InOperator;

            Assert.IsNotNull(inOp);

            CollectionAssert.AreEqual(new[] { new StringLiteral("first"), new StringLiteral("second"), new StringLiteral("third"), new StringLiteral("fourth") }, inOp.Right.Values.ToArray());
        }