Esempio n. 1
0
        public void TestSelectOrderBy()
        {
            CheckSelect("select * from area order by area_id ASC",
                        "SELECT *\r\nFROM area\r\nORDER BY area_id");

            StringBuilder expected = new StringBuilder();

            expected.Append("SELECT area.area_id, province.province_id, ");
            expected.Append("district.district_id, city.city_id\r\n");
            expected.Append("FROM area ");
            expected.Append("INNER JOIN province ON area.area_id = province.area_id ");
            expected.Append("INNER JOIN district ON province.province_id = district.province_id ");
            expected.Append("INNER JOIN city ON district.city_id = city.city_id\r\n");
            expected.Append("ORDER BY area.area_id, province.province_id, ");
            expected.Append("district.district_id, city.city_id");

            CheckSelect(@"select area.area_id, province.province_id, district.district_id, city.city_id
from area
join province on area.area_id=province.area_id
join district on province.province_id=district.province_id
join city on district.city_id=city.city_id
order by area.area_id,province.province_id,district.district_id,city.city_id",
                        expected.ToString());

            SelectStatement statement = Factory.CreateStatement(
                "select area.* from area") as SelectStatement;

            Assert.IsNotNull(statement);

            QueryExpression queryExpression = statement.SingleQueryExpression;

            Assert.IsNotNull(queryExpression);
            Assert.IsNull(queryExpression.OrderBy);

            MacroScopeParser parser     = Factory.CreateParser("area.area_id");
            IExpression      expression = parser.expression();

            Assert.IsNotNull(expression);

            OrderExpression orderExpression = new OrderExpression(expression);

            queryExpression.OrderBy = orderExpression;

            string sql = TestUtil.Stringify(statement);

            Assert.AreEqual("SELECT area.*\r\nFROM area\r\nORDER BY area.area_id",
                            sql);

            CheckSelect("SELECT * FROM fact ORDER BY subject, predicate desc, [object]",
                        "SELECT *\r\nFROM fact\r\nORDER BY subject, predicate DESC, [object]");
            CheckSelect(@"SELECT *
FROM fact
ORDER BY
subject ASC, predicate DESC, [object] ASC",
                        "SELECT *\r\nFROM fact\r\nORDER BY subject, predicate DESC, [object]");
        }
Esempio n. 2
0
        void CheckExpression(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.expression();

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