Exemple #1
0
        public void TestSearchCondition()
        {
            MacroScopeParser parser     = Factory.CreateParser("a != b");
            Expression       expression = parser.searchCondition() as Expression;

            Assert.IsNotNull(expression);
            Assert.AreEqual("a <> b", TestUtil.Stringify(expression));

            parser     = Factory.CreateParser("a + b > c");
            expression = parser.searchCondition() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("(a + b) > c", TestUtil.Stringify(expression));

            parser = Factory.CreateParser("m != all (select n from x)");
            PredicateExpression predicateExpression = parser.searchCondition()
                                                      as PredicateExpression;

            Assert.IsNotNull(predicateExpression);
            Assert.AreEqual("m <> ALL ( SELECT n\r\nFROM x )",
                            TestUtil.Stringify(predicateExpression));

            parser     = Factory.CreateParser("c is not null");
            expression = parser.searchCondition() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("c IS NOT NULL", TestUtil.Stringify(expression));

            parser     = Factory.CreateParser("1<>1 and 1<>1 or 1=1");
            expression = parser.searchCondition() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("((1 <> 1) AND (1 <> 1)) OR (1 = 1)",
                            TestUtil.Stringify(expression));

            parser     = Factory.CreateParser("1 = 1 or 1 <> 1 and 1 <> 1");
            expression = parser.searchCondition() as Expression;
            Assert.IsNotNull(expression);
            Assert.AreEqual("(1 = 1) OR ((1 <> 1) AND (1 <> 1))",
                            TestUtil.Stringify(expression));

            CheckSearchCondition("(1 = 1)", "1 = 1");

            CheckSearchCondition("NULL IS NULL");

            StringBuilder expected = new StringBuilder();

            expected.Append("((address.building_id = ");
            expected.Append("building.building_id) ");
            expected.Append("AND (building.settlement_id = settlement.settlement_id)) ");
            expected.Append("AND (settlement.village_id = village.village_id)");
            CheckSearchCondition(expected.ToString());

            CheckSearchCondition("updated >= 1");
            CheckSearchCondition("updated >= @threshold");
            CheckSearchCondition("updated >= :threshold");
            CheckSearchCondition("updated >= DATE()");
        }
Exemple #2
0
        void CheckSearchCondition(string from, string to)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            MacroScopeParser parser     = Factory.CreateParser(from);
            IExpression      expression = parser.searchCondition();

            Assert.IsNotNull(expression);
            Assert.AreEqual(to, TestUtil.Stringify(expression));
        }